2017-10-25 02:11:28 -07:00
|
|
|
import Component from '@ember/component';
|
2017-11-01 09:10:42 -07:00
|
|
|
import { inject } from '@ember/service';
|
2017-11-06 09:29:12 -08:00
|
|
|
import { getProperties, computed, set } from '@ember/object';
|
2017-10-25 02:11:28 -07:00
|
|
|
import ComputedProperty, { oneWay } from '@ember/object/computed';
|
|
|
|
import { baseCommentEditorOptions } from 'wherehows-web/constants';
|
2017-10-25 03:04:36 -07:00
|
|
|
import Notifications, { NotificationEvent } from 'wherehows-web/services/notifications';
|
2017-10-25 02:11:28 -07:00
|
|
|
|
|
|
|
export default class DatasetDeprecation extends Component {
|
|
|
|
tagName = 'div';
|
|
|
|
|
|
|
|
classNames = ['dataset-deprecation-toggle'];
|
|
|
|
|
2017-10-25 03:04:36 -07:00
|
|
|
/**
|
|
|
|
* References the application notifications service
|
|
|
|
* @memberof DatasetDeprecation
|
|
|
|
*/
|
|
|
|
notifications = <ComputedProperty<Notifications>>inject();
|
|
|
|
|
2017-10-25 02:11:28 -07:00
|
|
|
/**
|
2017-11-01 09:10:42 -07:00
|
|
|
* Flag indicating that the dataset is deprecated or otherwise
|
2017-10-25 02:11:28 -07:00
|
|
|
* @type {(null | boolean)}
|
|
|
|
* @memberof DatasetDeprecation
|
|
|
|
*/
|
|
|
|
deprecated: null | boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Working reference to the dataset's deprecated flag
|
|
|
|
* @memberof DatasetDeprecation
|
2017-11-01 09:10:42 -07:00
|
|
|
* @type {ComputedProperty<typeof DatasetDeprecation.deprecated>}
|
2017-10-25 02:11:28 -07:00
|
|
|
*/
|
|
|
|
deprecatedAlias = oneWay('deprecated');
|
|
|
|
|
|
|
|
/**
|
2017-11-01 09:10:42 -07:00
|
|
|
* Note accompanying the deprecation flag change
|
2017-10-25 02:11:28 -07:00
|
|
|
* @type {string}
|
|
|
|
* @memberof DatasetDeprecation
|
|
|
|
*/
|
|
|
|
deprecationNote: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Working reference to the dataset's deprecationNote
|
|
|
|
* @memberof DatasetDeprecation
|
2017-11-01 09:10:42 -07:00
|
|
|
* @type {ComputedProperty<typeof DatasetDeprecation.deprecationNote>}
|
2017-10-25 02:11:28 -07:00
|
|
|
*/
|
|
|
|
deprecationNoteAlias = oneWay('deprecationNote');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks the working / aliased copies of the deprecation properties diverge from the
|
|
|
|
* saved versions i.e. deprecationNoteAlias and deprecationAlias
|
|
|
|
* @type {ComputedProperty<boolean>}
|
|
|
|
* @memberof DatasetDeprecation
|
|
|
|
*/
|
|
|
|
isDirty: ComputedProperty<boolean> = computed(
|
|
|
|
'deprecatedAlias',
|
|
|
|
'deprecated',
|
|
|
|
'deprecationNote',
|
|
|
|
'deprecationNoteAlias',
|
|
|
|
function(this: DatasetDeprecation) {
|
|
|
|
const { deprecatedAlias, deprecated, deprecationNote, deprecationNoteAlias } = getProperties(this, [
|
|
|
|
'deprecatedAlias',
|
|
|
|
'deprecated',
|
|
|
|
'deprecationNote',
|
|
|
|
'deprecationNoteAlias'
|
|
|
|
]);
|
|
|
|
|
|
|
|
return deprecatedAlias !== deprecated || deprecationNoteAlias !== deprecationNote;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The action to be completed when a save is initiated
|
|
|
|
* @type {Function}
|
|
|
|
* @memberof DatasetDeprecation
|
|
|
|
*/
|
|
|
|
onUpdateDeprecation: Function;
|
|
|
|
|
|
|
|
editorOptions = {
|
|
|
|
...baseCommentEditorOptions,
|
|
|
|
placeholder: {
|
|
|
|
text: "You may provide a note about this dataset's deprecation status"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
/**
|
|
|
|
* Toggles the boolean value of deprecatedAlias
|
|
|
|
*/
|
|
|
|
toggleDeprecatedStatus(this: DatasetDeprecation) {
|
|
|
|
this.toggleProperty('deprecatedAlias');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invokes the save action with the updated values for
|
|
|
|
* deprecated and deprecationNote
|
|
|
|
*/
|
2017-10-25 03:04:36 -07:00
|
|
|
async onSave(this: DatasetDeprecation) {
|
|
|
|
const { deprecatedAlias, deprecationNoteAlias, notifications: { notify } } = getProperties(this, [
|
2017-10-25 02:11:28 -07:00
|
|
|
'deprecatedAlias',
|
2017-10-25 03:04:36 -07:00
|
|
|
'deprecationNoteAlias',
|
|
|
|
'notifications'
|
2017-10-25 02:11:28 -07:00
|
|
|
]);
|
|
|
|
const { onUpdateDeprecation } = this;
|
|
|
|
|
|
|
|
if (onUpdateDeprecation) {
|
2017-11-06 09:29:12 -08:00
|
|
|
const noteValue = deprecatedAlias ? deprecationNoteAlias : '';
|
|
|
|
|
2017-10-25 03:04:36 -07:00
|
|
|
try {
|
2017-11-06 09:29:12 -08:00
|
|
|
await onUpdateDeprecation(deprecatedAlias, noteValue);
|
|
|
|
set(this, 'deprecationNoteAlias', noteValue);
|
|
|
|
|
2017-10-25 03:04:36 -07:00
|
|
|
notify(NotificationEvent.success, {
|
|
|
|
content: 'Successfully updated deprecation status'
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
notify(NotificationEvent.error, {
|
|
|
|
content: `An error occurred: ${e.message}`
|
|
|
|
});
|
|
|
|
}
|
2017-10-25 02:11:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|