From 98955eb19db4eac6f1137912517df61a73937a5b Mon Sep 17 00:00:00 2001 From: Josh Worden Date: Thu, 18 Oct 2018 14:48:53 -0500 Subject: [PATCH 1/3] Remove hard-coded values from form --- app/app/components/submit-modal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() { From 344326de0aa60a8af923d6bb6190227d11c9c88a Mon Sep 17 00:00:00 2001 From: Josh Worden Date: Thu, 18 Oct 2018 15:07:41 -0500 Subject: [PATCH 2/3] Ensure section ids are unique --- .../controllers/display/company/edit/categories.js | 13 ++++++------- app/app/controllers/display/company/review.js | 5 ----- app/app/routes/display/company.js | 3 ++- app/app/templates/display/company/review.hbs | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) 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..3759de5 100644 --- a/app/app/controllers/display/company/review.js +++ b/app/app/controllers/display/company/review.js @@ -6,9 +6,4 @@ export default Controller.extend({ 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); - }), - }); 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/templates/display/company/review.hbs b/app/app/templates/display/company/review.hbs index b4788a7..ceff3a8 100644 --- a/app/app/templates/display/company/review.hbs +++ b/app/app/templates/display/company/review.hbs @@ -22,7 +22,7 @@

Categories

- {{ review-section-diff current=model.submission.payload.sectionIds old=oldIds }} + {{ review-section-diff current=model.submission.payload.sectionIds old=model.company.sectionIds }}
From 4ee667b5df1dcd0f1a0cfc8a72d8bae2a063a27f Mon Sep 17 00:00:00 2001 From: Josh Worden Date: Thu, 18 Oct 2018 15:41:17 -0500 Subject: [PATCH 3/3] make done work --- app/app/controllers/display/company/review.js | 24 ++++++++++++++++++- app/app/gql/mutations/complete.graphql | 7 ++++++ app/app/styles/app.scss | 6 +++++ app/app/templates/display/company/review.hbs | 10 +++++++- .../display/company/review/fields.hbs | 4 ++-- graph/src/definitions/index.js | 10 +++++++- graph/src/mongodb.js | 2 +- 7 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 app/app/gql/mutations/complete.graphql diff --git a/app/app/controllers/display/company/review.js b/app/app/controllers/display/company/review.js index 3759de5..48d95ae 100644 --- a/app/app/controllers/display/company/review.js +++ b/app/app/controllers/display/company/review.js @@ -1,9 +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')}
`; }), + 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/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 ceff3a8..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}}

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 } }), };