Skip to content

Commit

Permalink
refactor(cataloging/bulk-changes): new and namespaced bulk change ter… (
Browse files Browse the repository at this point in the history
#1136)

* New and namespaced bulk change terms in vocab/platform
* Add constants for bulk terms
  • Loading branch information
olovy authored Oct 29, 2024
1 parent 8edb3fa commit ad2f9a3
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 95 deletions.
5 changes: 4 additions & 1 deletion cataloging/src/components/care/bulk-changes-header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import FormBuilder from "@/components/care/form-builder.vue";
import IdPill from "@/components/shared/id-pill.vue";
import * as StringUtil from 'lxljs/string.js';
import {mapGetters} from "vuex";
import {
STATUS_KEY,
} from "@/utils/bulk.js";
export default {
name: 'bulk-changes-header.vue',
Expand Down Expand Up @@ -31,7 +34,7 @@ export default {
return this.currentBulkChange['@id'];
},
status() {
return StringUtil.getLabelByLang(this.currentBulkChange.bulkChangeStatus, this.user.settings.language, this.resources);
return StringUtil.getLabelByLang(this.currentBulkChange[STATUS_KEY], this.user.settings.language, this.resources);
},
},
methods: {
Expand Down
84 changes: 44 additions & 40 deletions cataloging/src/components/care/bulk-changes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import TargetFormBuilder from '@/components/care/target-form-builder.vue';
import Preview from '@/components/care/preview.vue';
import BulkChangesHeader from "@/components/care/bulk-changes-header.vue";
import { mapGetters } from 'vuex';
import {cloneDeep, get, isEmpty, isEqual} from 'lodash-es';
import { cloneDeep, get, isEmpty, isEqual } from 'lodash-es';
import emptyTemplate from './templates/empty.json';
import toolbar from "@/components/inspector/bulkchange-toolbar.vue";
import {labelByLang, translatePhrase} from "@/utils/filters.js";
import { labelByLang, translatePhrase } from "@/utils/filters.js";
import * as LayoutUtil from '@/utils/layout';
import Inspector from "@/views/Inspector.vue";
import ModalComponent from '@/components/shared/modal-component.vue';
Expand All @@ -18,7 +18,15 @@ import * as RecordUtil from "@/utils/record.js";
import * as LxlDataUtil from "lxljs/data.js";
import * as HistoryUtil from "@/utils/history.js";
import ReverseRelations from "../inspector/reverse-relations.vue";
import {appendIds} from "../../utils/data.js";
import { appendIds } from "../../utils/data.js";
import {
CHANGE_SPEC_KEY,
MATCH_FORM_KEY,
SHOULD_UPDATE_TIMESTAMP_KEY,
STATUS_KEY,
TARGET_FORM_KEY,
Status,
} from "@/utils/bulk.js";
export default {
name: 'bulk-changes.vue',
Expand Down Expand Up @@ -89,10 +97,10 @@ export default {
return this.inspector.data.mainEntity;
},
formObj() {
return this.isActive('form') ? this.inspector.data.mainEntity : this.currentSpec.matchForm;
return this.isActive('form') ? this.inspector.data.mainEntity : this.currentSpec[MATCH_FORM_KEY];
},
targetFormObj() {
return this.isActive('targetForm') ? this.inspector.data.mainEntity : this.currentSpec.targetForm;
return this.isActive('targetForm') ? this.inspector.data.mainEntity : this.currentSpec[TARGET_FORM_KEY];
},
formTitle() {
return `${this.steps.indexOf('form') + 1}. ${translatePhrase('Selection')}`
Expand All @@ -116,35 +124,35 @@ export default {
return this.activeStep === this.steps[0];
},
isDraft() {
return this.currentBulkChange.bulkChangeStatus === 'DraftBulkChange';
return this.currentBulkChange[STATUS_KEY] === Status.Draft;
},
isReady() {
return this.currentBulkChange.bulkChangeStatus === 'ReadyBulkChange';
return this.currentBulkChange[STATUS_KEY] === Status.Ready;
},
isFinished() {
return this.currentBulkChange.bulkChangeStatus === 'CompletedBulkChange'
|| this.currentBulkChange.bulkChangeStatus === 'FailedBulkChange';
return this.currentBulkChange[STATUS_KEY] === Status.Completed
|| this.currentBulkChange[STATUS_KEY] === Status.Failed;
},
isRunningOrFinished() {
return this.isFinished
|| this.currentBulkChange.bulkChangeStatus === 'RunningBulkChange';
|| this.currentBulkChange[STATUS_KEY] === Status.Running;
},
statusLabel() {
return StringUtil.getLabelByLang(this.currentBulkChange.bulkChangeStatus, this.user.settings.language, this.resources);
return StringUtil.getLabelByLang(this.currentBulkChange[STATUS_KEY], this.user.settings.language, this.resources);
},
loudOrSilentLabel() {
return translatePhrase('Export changed records (update change date)');
},
isLoud() {
return this.currentBulkChange.bulkChangeMetaChanges === "LoudBulkChange";
return this.currentBulkChange[SHOULD_UPDATE_TIMESTAMP_KEY] === true;
},
shouldExportAffected() {
return this.isLoud;
},
hasUnsavedChanges() {
if (this.lastFetchedSpec && this.isDraft) {
const matchFormEqual = isEqual(this.formObj, this.lastFetchedSpec.matchForm);
const targetFormEqual = isEqual(this.targetFormObj, this.lastFetchedSpec.targetForm);
const matchFormEqual = isEqual(this.formObj, this.lastFetchedSpec[MATCH_FORM_KEY]);
const targetFormEqual = isEqual(this.targetFormObj, this.lastFetchedSpec[MATCH_FORM_KEY]);
return !matchFormEqual || !targetFormEqual;
}
return false;
Expand All @@ -164,17 +172,17 @@ export default {
this.currentBulkChange = mainEntity;
this.currentBulkChange.label = '<namn>-' + this.getDateString();
this.currentSpec = this.currentBulkChange.bulkChangeSpecification;
this.currentSpec = this.currentBulkChange[CHANGE_SPEC_KEY];
//TODO: Allow differing initial match and target forms. + Make it work with appended _ids.
this.record = record;
this.lastFetchedSpec = this.currentSpec;
DataUtil.fetchMissingLinkedToQuoted(this.currentBulkChange, this.$store);
this.setActive(this.steps[0]);
const initialForm = appendIds(mainEntity.bulkChangeSpecification.matchForm);
this.currentSpec.matchForm = initialForm;
this.currentSpec.targetForm = initialForm;
const initialForm = appendIds(mainEntity[CHANGE_SPEC_KEY][MATCH_FORM_KEY]);
this.currentSpec[MATCH_FORM_KEY] = initialForm;
this.currentSpec[TARGET_FORM_KEY] = initialForm;
this.setInspectorData(initialForm);
this.$store.dispatch('pushInspectorEvent', {
name: 'record-control',
Expand All @@ -184,10 +192,10 @@ export default {
initFromRecord() {
this.setActive(this.steps[0]);
// FIXME: remove emptyTemplate
const initial = emptyTemplate.mainEntity.bulkChangeSpecification.matchForm;
const initial = emptyTemplate.mainEntity[CHANGE_SPEC_KEY][MATCH_FORM_KEY];
this.setInspectorData(initial);
this.currentSpec.matchForm = initial;
this.currentSpec.targetForm = initial; //FIXME: to avoid undefined on init
this.currentSpec[MATCH_FORM_KEY] = initial;
this.currentSpec[TARGET_FORM_KEY] = initial; //FIXME: to avoid undefined on init
this.fetchRecord(this.documentId);
},
fetchRecord(fnurgel) {
Expand Down Expand Up @@ -217,16 +225,16 @@ export default {
if (typeof result !== 'undefined') {
const bulkChange = LxlDataUtil.splitJson(result);
this.currentBulkChange = bulkChange.mainEntity;
this.currentSpec = this.currentBulkChange.bulkChangeSpecification;
this.currentSpec = this.currentBulkChange[CHANGE_SPEC_KEY];
this.record = bulkChange.record;
this.lastFetchedSpec = cloneDeep(this.currentSpec);
if (this.isActive('form')) {
this.setInspectorData(this.currentSpec.matchForm);
this.setInspectorData(this.currentSpec[MATCH_FORM_KEY]);
} else if (this.isActive('targetForm')){
this.setInspectorData(this.currentSpec.targetForm)
this.setInspectorData(this.currentSpec[TARGET_FORM_KEY])
} else {
this.setInspectorData(this.currentSpec.matchForm)
this.setInspectorData(this.currentSpec[MATCH_FORM_KEY])
}
if (this.isDraft) {
this.$store.dispatch('pushInspectorEvent', {
Expand Down Expand Up @@ -256,18 +264,18 @@ export default {
},
onInactiveForm() {
let form = DataUtil.appendIds(cloneDeep(this.inspector.data.mainEntity));
if (isEqual(form, this.currentSpec.matchForm)) {
this.setInspectorData(this.currentSpec.targetForm);
if (isEqual(form, this.currentSpec[MATCH_FORM_KEY])) {
this.setInspectorData(this.currentSpec[TARGET_FORM_KEY]);
} else {
this.setInspectorData(form);
this.currentSpec.matchForm = form;
this.currentSpec[MATCH_FORM_KEY] = form;
}
},
onInactiveTargetForm() {
if (this.activeStep === 'form') {
this.setInspectorData(this.currentSpec.matchForm);
this.setInspectorData(this.currentSpec[MATCH_FORM_KEY]);
}
this.currentSpec.targetForm = cloneDeep(this.inspector.data.mainEntity);
this.currentSpec[TARGET_FORM_KEY] = cloneDeep(this.inspector.data.mainEntity);
},
reset() {
this.$store.dispatch('setInspectorStatusValue', {
Expand Down Expand Up @@ -331,11 +339,7 @@ export default {
this.showConfirmRunModal = true;
},
toggleExportAffected() {
if (this.shouldExportAffected) {
this.currentBulkChange.bulkChangeMetaChanges = "SilentBulkChange";
} else {
this.currentBulkChange.bulkChangeMetaChanges = "LoudBulkChange";
}
this.currentBulkChange[SHOULD_UPDATE_TIMESTAMP_KEY] = !!this.shouldExportAffected;
},
save() {
this.resetLastAdded();
Expand Down Expand Up @@ -367,8 +371,8 @@ export default {
const formChangeset = result.changeSets[1];
const [formDisplayData, formDisplayPaths] = HistoryUtil.buildDisplayData(
this.currentSpec.matchForm,
this.currentSpec.targetForm,
this.currentSpec[MATCH_FORM_KEY],
this.currentSpec[TARGET_FORM_KEY],
formChangeset.addedPaths,
formChangeset.removedPaths,
(s) => StringUtil.getLabelByLang(s, this.user.settings.language, this.resources),
Expand Down Expand Up @@ -422,12 +426,12 @@ export default {
},
doRun() {
this.closeConfirmRunModal();
this.setRunStatus('ReadyBulkChange');
this.setRunStatus(Status.Ready);
this.save();
this.setActive('preview');
},
setAsDraft() {
this.setRunStatus('DraftBulkChange');
this.setRunStatus(Status.Draft);
},
openIdListModal() {
this.idListUri = '';
Expand Down Expand Up @@ -463,7 +467,7 @@ export default {
this.getPreviewFromUrl(`${this.settings.apiPath}${this.previousPreviewLink['@id']}`);
},
setRunStatus(status) {
this.currentBulkChange.bulkChangeStatus = status;
this.currentBulkChange[STATUS_KEY] = status;
},
resetPreviewData() {
this.fullPreview = {};
Expand Down
3 changes: 2 additions & 1 deletion cataloging/src/components/care/preview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EntitySummary from "@/components/shared/entity-summary.vue";
import {asFnurgelLink, translatePhrase} from "@/utils/filters.js";
import {offset} from "@floating-ui/dom";
import * as StringUtil from "../../../../lxljs/string.js";
import { Status } from "@/utils/bulk.js";
export default {
name: 'preview',
Expand Down Expand Up @@ -79,7 +80,7 @@ export default {
}
},
completedLabel() {
return StringUtil.getLabelByLang('CompletedBulkChange', this.user.settings.language, this.resources)
return StringUtil.getLabelByLang(Status.Completed, this.user.settings.language, this.resources)
}
},
emits: ['onInactive', 'onActive'],
Expand Down
14 changes: 7 additions & 7 deletions cataloging/src/components/care/templates/empty.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"mainEntity": {
"@type": "BulkChange",
"@type": "bulk:Job",
"@id": "https://id.kb.se/TEMPID#it",
"label": "",
"comment": "",
"bulkChangeStatus": "DraftBulkChange",
"bulkChangeMetaChanges": "SilentBulkChange",
"bulkChangeSpecification": {
"@type": "FormSpecification",
"matchForm": {
"bulk:status": "bulk:Draft",
"bulk:shouldUpdateModifiedTimestamp": false,
"bulk:changeSpec": {
"@type": "bulk:Update",
"bulk:matchForm": {
"@type": "Instance"
},
"targetForm": {
"bulk:targetForm": {
"@type": "Instance"
}
}
Expand Down
4 changes: 2 additions & 2 deletions cataloging/src/components/mixins/item-mixin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as VocabUtil from 'lxljs/vocab';
import * as StringUtil from 'lxljs/string';
import * as DataUtil from '@/utils/data';
import * as RecordUtil from '@/utils/record';
import { DELETE_ON_SAVE } from "@/store";
import { JOB_TYPE } from "@/utils/bulk.js";
export default {
props: {
Expand Down Expand Up @@ -184,7 +184,7 @@ export default {
const uriParts = this.recordId.split('/');
const fnurgel = uriParts[uriParts.length - 1];
if (this.recordType === 'BulkChange') {
if (this.recordType === JOB_TYPE) {
return `/directory-care/bulkchanges/${fnurgel}`;
}
Expand Down
3 changes: 2 additions & 1 deletion cataloging/src/components/search/search-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import PropertyMappings from '@/resources/json/propertymappings.json';
import { buildQueryString } from '@/utils/http';
import { translatePhrase } from '@/utils/filters';
import RemoteDatabases from '@/components/search/remote-databases.vue';
import { JOB_TYPE } from "@/utils/bulk.js";
export default {
name: 'search-form',
Expand Down Expand Up @@ -199,7 +200,7 @@ export default {
]),
dataSetFilters() {
if (this.user.settings.activeSigel === 'SEK') {
const extraFilter = { value: 'BulkChange', label: 'Bulk change' };
const extraFilter = { value: JOB_TYPE, label: 'Bulk change' };
return [...this.settings.dataSetFilters.libris, extraFilter];
} else {
return this.settings.dataSetFilters.libris;
Expand Down
3 changes: 2 additions & 1 deletion cataloging/src/components/shared/entity-summary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TypeIcon from '@/components/shared/type-icon.vue';
import SummaryNode from '@/components/shared/summary-node.vue';
import IdPill from '@/components/shared/id-pill.vue';
import LensMixin from '../mixins/lens-mixin.vue';
import { JOB_TYPE } from "@/utils/bulk.js";
export default {
mixins: [LensMixin, OverflowMixin],
Expand Down Expand Up @@ -186,7 +187,7 @@ export default {
const uriParts = this.recordId.split('/');
const fnurgel = uriParts[uriParts.length - 1];
if (this.recordType === 'BulkChange') {
if (this.recordType === JOB_TYPE) {
return `/directory-care/bulkchanges/${fnurgel}`;
}
Expand Down
Loading

0 comments on commit ad2f9a3

Please sign in to comment.