diff --git a/app/app/components/submit-modal.js b/app/app/components/submit-modal.js index d46248b..05d93b5 100644 --- a/app/app/components/submit-modal.js +++ b/app/app/components/submit-modal.js @@ -32,8 +32,8 @@ const filterModel = (model = {}) => { export default Component.extend(ComponentQueryManager, ActionMixin, { model: null, - name: 'j', // null, - email: 'j@lol.io', // null, + name: null, + email: null, isOpen: false, isInvalid: computed('name', 'email', function() { diff --git a/app/app/controllers/display/company/edit/categories.js b/app/app/controllers/display/company/edit/categories.js index f40898b..6b454cf 100644 --- a/app/app/controllers/display/company/edit/categories.js +++ b/app/app/controllers/display/company/edit/categories.js @@ -12,10 +12,7 @@ const flatten = (sections, selected = []) => { }; export default Controller.extend({ - selectedIds: computed('model.company.scheduledWebsiteSections.edges', function() { - return this.get('model.company.scheduledWebsiteSections.edges').map(({ node }) => node.id); - }), - selected: computed.reads('selectedIds'), + selected: computed.reads('model.company.sectionIds'), sections: computed('model.sections.[],selected.[]', function() { return flatten(this.get('model.sections'), this.get('selected')); }), @@ -33,12 +30,14 @@ export default Controller.extend({ this.transitionToRoute('display.company.edit'); }, select(node) { - if (!this.get('model.company.sectionIds')) this.set('model.company.sectionIds', this.get('selected')); this.get('model.company.sectionIds').push(parseInt(node.id)); + const unique = this.get('model.company.sectionIds').filter((v, i, a) => a.indexOf(v) === i); + this.set('model.company.sectionIds', unique); }, deselect(node) { - if (!this.get('model.company.sectionIds')) this.set('model.company.sectionIds', this.get('selected')); - this.set('model.company.sectionIds', this.get('selected').without(node.id)); + const unique = this.get('model.company.sectionIds').filter((v, i, a) => a.indexOf(v) === i); + const toSet = unique.filter(v => v !== parseInt(node.id)); + this.set('model.company.sectionIds', toSet); }, } }); diff --git a/app/app/controllers/display/company/review.js b/app/app/controllers/display/company/review.js index 94680fa..48d95ae 100644 --- a/app/app/controllers/display/company/review.js +++ b/app/app/controllers/display/company/review.js @@ -1,14 +1,31 @@ import Controller from 'cuf/controllers/display/company'; import { computed } from '@ember/object'; +import { inject } from '@ember/service'; + +import mutation from 'cuf/gql/mutations/complete'; export default Controller.extend({ - options: { toolbarButtons: [] }, + apollo: inject(), body: computed('model.submission.payload.body', function() { return `
${this.get('model.submission.payload.body')}
`; }), - - oldIds: computed('model.company.scheduledWebsiteSections.edges', function() { - return this.get('model.company.scheduledWebsiteSections.edges').map(({ node }) => node.id); - }), - + init() { + this._super(...arguments); + this.set('options', { + toolbarButtons: [] + }); + }, + actions: { + async done() { + try { + const id = this.get('model.submission.id'); + await this.get('apollo').mutate({ mutation, variables: { id } }); + this.get('notify').info('Marked as done!'); + this.set('model.submission.reviewed', true); + } catch (e) { + console.error(e); // eslint-disable-line no-console + this.get('notify').alert('Something went wrong -- please try again!', { closeAfter: null }); + } + }, + }, }); diff --git a/app/app/gql/mutations/complete.graphql b/app/app/gql/mutations/complete.graphql new file mode 100644 index 0000000..f02d47a --- /dev/null +++ b/app/app/gql/mutations/complete.graphql @@ -0,0 +1,7 @@ +mutation Complete($id: String!) { + complete(id: $id) { + result { + ok + } + } +} diff --git a/app/app/routes/display/company.js b/app/app/routes/display/company.js index b81e18c..08225e1 100644 --- a/app/app/routes/display/company.js +++ b/app/app/routes/display/company.js @@ -9,6 +9,7 @@ export default Route.extend(RouteQueryManager, { return this.get('apollo').watchQuery({ query, variables, fetchPolicy: 'cache-and-network' }, 'base4PlatformContentHash'); }, afterModel(model) { - model.set('sections', model.get('sections') || []); + const sectionIds = model.get('scheduledWebsiteSections.edges').map(({ node }) => node.id); + model.set('sectionIds', sectionIds); }, }); diff --git a/app/app/styles/app.scss b/app/app/styles/app.scss index aedac15..4a21d6b 100644 --- a/app/app/styles/app.scss +++ b/app/app/styles/app.scss @@ -43,3 +43,9 @@ body.transitioning { padding: 1em; min-height: 8em; } + +.field-modified { + background-color: rgba(24, 188, 156, 0.1) !important; + border: 1px solid rgb(24, 188, 156); + border-right: none; +} diff --git a/app/app/templates/display/company/review.hbs b/app/app/templates/display/company/review.hbs index b4788a7..2aa03ea 100644 --- a/app/app/templates/display/company/review.hbs +++ b/app/app/templates/display/company/review.hbs @@ -6,7 +6,15 @@

When you are finished making changes, click the "Done" button.

- + {{#if model.submission.reviewed}} + + {{else}} + + {{/if}}

@@ -22,7 +30,7 @@

Categories

- {{ review-section-diff current=model.submission.payload.sectionIds old=oldIds }} + {{ review-section-diff current=model.submission.payload.sectionIds old=model.company.sectionIds }}
diff --git a/app/app/templates/display/company/review/fields.hbs b/app/app/templates/display/company/review/fields.hbs index 4fa4862..4d2750a 100644 --- a/app/app/templates/display/company/review/fields.hbs +++ b/app/app/templates/display/company/review/fields.hbs @@ -6,11 +6,11 @@
{{#if (eq field.type "long")}} -
+
{{ froala-editor content=body options=options }}
{{else}} -
+
{{ get model.submission.payload field.key }}
{{/if}} diff --git a/graph/src/definitions/index.js b/graph/src/definitions/index.js index a3acf57..b5feeed 100644 --- a/graph/src/definitions/index.js +++ b/graph/src/definitions/index.js @@ -13,10 +13,18 @@ module.exports = gql` type Mutation { company(input: CompanyUpdateInput!): CompanyUpdateSubmission! - complete(id: String!): String! + complete(id: String!): MongoUpdate! singleUpload(file: Upload!): String! } + type MongoUpdate { + result: MongoUpdateStatus + } + + type MongoUpdateStatus { + ok: Int! + } + enum CompanyTypes { Company Agency diff --git a/graph/src/mongodb.js b/graph/src/mongodb.js index 9773b26..c7c4edd 100644 --- a/graph/src/mongodb.js +++ b/graph/src/mongodb.js @@ -12,5 +12,5 @@ module.exports = { connect: () => promise, retrieve: id => client.db().collection('submission').findOne({ _id: new ObjectId(id) }), insert: payload => client.db().collection('submission').insertOne(payload), - complete: id => client.db().collection('submission').updateOne({ _id: id }, { $set: { reviewed: true } }), + complete: id => client.db().collection('submission').updateOne({ _id: new ObjectId(id) }, { $set: { reviewed: true } }), };