Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dictionaryId to MdJSON export dataDictionary object #707

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 37 additions & 39 deletions app/models/dictionary.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,59 @@
import { attr } from '@ember-data/model';
import { Copyable } from 'ember-copy'
import { Copyable } from 'ember-copy';
import { alias } from '@ember/object/computed';
import Model from 'mdeditor/models/base';
import {
validator,
buildValidations
} from 'ember-cp-validations';
import { validator, buildValidations } from 'ember-cp-validations';
import EmberObject, { computed } from '@ember/object';
import config from 'mdeditor/config/environment';

const {
APP: {
defaultProfileId
}
APP: { defaultProfileId },
} = config;

const Validations = buildValidations({
'json.dictionaryId': validator(
'presence', {
presence: true,
ignoreBlank: true,
}),
'json.dataDictionary.dictionaryId': validator('presence', {
presence: true,
ignoreBlank: true,
}),
'json.dataDictionary.citation.title': validator('presence', {
presence: true,
ignoreBlank: true
ignoreBlank: true,
}),
'json.dataDictionary.subject': [validator('presence', {
'json.dataDictionary.subject': [
validator('presence', {
presence: true,
ignoreBlank: true
ignoreBlank: true,
}),
validator('array-required', {
track: []
})
]
track: [],
}),
],
});

const JsonDefault = EmberObject.extend({
init() {
this._super(...arguments);
this.setProperties({
dictionaryId: null,
dataDictionary: {
dictionaryId: null,

citation: {
title: null,
date: [{
date: new Date()
.toISOString(),
dateType: 'creation'
}]
date: [
{
date: new Date().toISOString(),
dateType: 'creation',
},
],
},
description: '',
subject: [],
responsibleParty: {},
domain: [],
entity: []
entity: [],
},
});
}
},
});

export default Model.extend(Validations, Copyable, {
Expand All @@ -77,21 +74,21 @@ export default Model.extend(Validations, Copyable, {
},

profile: attr('string', {
defaultValue: defaultProfileId
defaultValue: defaultProfileId,
}),
json: attr('json', {
defaultValue() {
return JsonDefault.create();
}
},
}),
dateUpdated: attr('date', {
defaultValue() {
return new Date();
}
},
}),

title: alias('json.dataDictionary.citation.title'),
dictionaryId: alias('json.dictionaryId'),
dictionaryId: alias('json.dataDictionary.dictionaryId'),

icon: 'book',

Expand All @@ -109,23 +106,23 @@ export default Model.extend(Validations, Copyable, {
let errors = [];
let result = mdjson.validateDictionary(this).errors;

if(result) {
if (result) {
errors.pushObject({
title: 'Default Dictionary Validation',
errors: result
errors: result,
});
}

this.customSchemas.forEach(schema => {
this.customSchemas.forEach((schema) => {
const validator = schema.validator;

if(validator.validate(schema.rootSchema, this.cleanJson)) {
if (validator.validate(schema.rootSchema, this.cleanJson)) {
return;
}

errors.pushObject({
title: schema.title,
errors: validator.errors
errors: validator.errors,
});
});

Expand All @@ -137,10 +134,11 @@ export default Model.extend(Validations, Copyable, {
let json = EmberObject.create(current);
let name = current.dataDictionary.citation.title;
json.set('dataDictionary.citation.title', `Copy of ${name}`);
json.set('dictionaryId', null);
//TODO:copy needs a new ID
json.set('dataDictionary.dictionaryId', null);

return this.store.createRecord('dictionary', {
json: json
json: json,
});
}
},
});
Loading