Skip to content

Commit

Permalink
Merge pull request #1 from solocommand/updates
Browse files Browse the repository at this point in the history
Updates
  • Loading branch information
solocommand authored Oct 18, 2018
2 parents ed2aed5 + 4ee667b commit 7fc4431
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/app/components/submit-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const filterModel = (model = {}) => {
export default Component.extend(ComponentQueryManager, ActionMixin, {
model: null,

name: 'j', // null,
email: '[email protected]', // null,
name: null,
email: null,

isOpen: false,
isInvalid: computed('name', 'email', function() {
Expand Down
13 changes: 6 additions & 7 deletions app/app/controllers/display/company/edit/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}),
Expand All @@ -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);
},
}
});
29 changes: 23 additions & 6 deletions app/app/controllers/display/company/review.js
Original file line number Diff line number Diff line change
@@ -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 `<div contenteditable=false>${this.get('model.submission.payload.body')}</div>`;
}),

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 });
}
},
},
});
7 changes: 7 additions & 0 deletions app/app/gql/mutations/complete.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mutation Complete($id: String!) {
complete(id: $id) {
result {
ok
}
}
}
3 changes: 2 additions & 1 deletion app/app/routes/display/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
6 changes: 6 additions & 0 deletions app/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
12 changes: 10 additions & 2 deletions app/app/templates/display/company/review.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
<p>When you are finished making changes, click the "Done" button.</p>
</div>
<div class="col-12 col-md-4 col-lg-3 col-xl-2">
<button class="btn btn-block btn-success">{{entypo-icon "save"}} Done</button>
{{#if model.submission.reviewed}}
<button class="btn btn-block btn-outline-success disabled">
{{entypo-icon "check"}} <span class="d-none d-md-inline">Done!</span>
</button>
{{else}}
<button class="btn btn-block btn-primary" {{ action "done" }}>
{{entypo-icon "check"}} <span class="d-none d-md-inline">Mark as done</span>
</button>
{{/if}}
</div>
</div>
<hr>
Expand All @@ -22,7 +30,7 @@
<div class="col-12 col-lg-4 col-xl-3 my-3">
<div class="card mb-3">
<h4 class="h6 card-header">Categories</h4>
{{ review-section-diff current=model.submission.payload.sectionIds old=oldIds }}
{{ review-section-diff current=model.submission.payload.sectionIds old=model.company.sectionIds }}
<div class="card-body"></div>
</div>
<div class="card mb-3">
Expand Down
4 changes: 2 additions & 2 deletions app/app/templates/display/company/review/fields.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
<label for="{{ field.key }}-input">{{ field.label }}</label>
<div class="input-group">
{{#if (eq field.type "long")}}
<div class="form-control {{ if (eq (get model.company field.key) (get model.submission.payload field.key)) "text-muted" "border-success" }}" style="height: inherit;">
<div class="form-control {{ if (eq (get model.company field.key) (get model.submission.payload field.key)) "text-muted" "field-modified" }}" style="height: inherit;">
{{ froala-editor content=body options=options }}
</div>
{{else}}
<div readonly class="form-control form-control-plaintext {{ if (eq (get model.company field.key) (get model.submission.payload field.key)) "text-muted" "border-success" }}">
<div readonly class="form-control form-control-plaintext {{ if (eq (get model.company field.key) (get model.submission.payload field.key)) "text-muted" "field-modified" }}">
{{ get model.submission.payload field.key }}
</div>
{{/if}}
Expand Down
10 changes: 9 additions & 1 deletion graph/src/definitions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion graph/src/mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }),
};

0 comments on commit 7fc4431

Please sign in to comment.