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

Integrating Pages API on content/pages route under admin #718

Merged
merged 1 commit into from Aug 21, 2017
Jump to file or symbol
Failed to load files and symbols.
+76 −57
Diff settings

Always

Just for now

Integrate Pages API on admin/content/pages route

  • Loading branch information...
harshitagupta30 committed Aug 18, 2017
commit 26fb73be76febbf5642c638970b9579774557958
@@ -70,9 +70,21 @@ export default Component.extend(FormMixin, {
},
actions: {
submit() {
submit(data) {
this.onValid(() => {
this.sendAction('save', data);
});
},
deletePage(data) {

This comment has been minimized.

@geekyd

geekyd Aug 18, 2017

Member

Good job! After deletion hide the form. Everything else looks good!

@geekyd

geekyd Aug 18, 2017

Member

Good job! After deletion hide the form. Everything else looks good!

if (!this.get('isCreate')) {
data.destroyRecord();
this.set('isFormOpen', false);
}
},
close() {
if (this.get('isCreate')) {
this.set('isFormOpen', false);
}
}
}
});
@@ -1,23 +1,31 @@
import Ember from 'ember';
import { find, map, uniqBy } from 'lodash';
const { Controller, computed } = Ember;
export default Controller.extend({
footerPages: computed.filterBy('model', 'menu', 'footer'),
footerPages: computed.filterBy('model', 'place', 'footer'),
eventPages: computed.filterBy('model', 'menu', 'event'),
places: computed('model', function() {
const data = this.get('model');
return map(uniqBy(data, 'menu'), 'menu');
}),
eventPages: computed.filterBy('model', 'place', 'event'),
actions: {
updateCurrentPage(url) {
var form = find(this.get('model'), { path: url });
updateCurrentPage(page, type) {
if (type === 'create') {
this.set('isCreate', true);
this.set('currentForm', this.get('store').createRecord('page'));
} else {
this.set('isCreate', false);
this.set('currentForm', page);
}
this.set('isFormOpen', true);
this.set('currentForm', form);
},
savePage(page) {
page.save()
.then(() => {
this.notify.success(this.l10n.t('Page details have been saved successfully.'));
})
.catch(()=> {
this.notify.error(this.l10n.t('An unexpected error has occured. Page Details not saved.'));
});
}
}
});
View
@@ -0,0 +1,12 @@
import attr from 'ember-data/attr';
import ModelBase from 'open-event-frontend/models/base';
export default ModelBase.extend({
name : attr('string'),
title : attr('string'),
url : attr('string'),
description : attr('string'),
language : attr('string'),
index : attr('number', { defaultValue: 0 }),
place : attr('string')
});
@@ -8,32 +8,6 @@ export default Route.extend({
},
model() {
return [
{
menu : 'footer',
name : 'Privacy Policy',
title : 'Privacy Policy',
path : '/privacy-policy',
description : '<h1>Privacy Policy</h1><p>Blah. Blah. Blah</p>',
position : 1,
language : 'en'
}, {
menu : 'event',
name : 'Locations',
title : 'Privacy Policy',
path : '/loc',
description : '<h1>Privacy Policy</h1><p>Blah. Blah. Blah</p>',
position : 1,
language : 'en'
}, {
menu : 'event',
name : 'Maps',
title : 'Privacy Policy',
path : '/map',
description : '<h1>Privacy Policy</h1><p>Blah. Blah. Blah</p>',
position : 1,
language : 'en'
}
];
return this.get('store').findAll('page');
}
});
@@ -6,7 +6,7 @@
<h3 class="ui header">{{t 'Pages'}}</h3>
</div>
<div class="column eight wide right aligned">
<button class="ui blue button" name="button">{{t 'Create Page'}}</button>
<button class="ui blue button" name="button" {{action 'updateCurrentPage' page 'create'}}>{{t 'Create Page'}}</button>
</div>
</div>
<div class="row">
@@ -17,7 +17,7 @@
{{#each eventPages as |page|}}
<div class="row">
<div class="column">
<div role="button" class="ui segment" {{action 'updateCurrentPage' page.path}}>
<div role="button" class="ui segment" {{action 'updateCurrentPage' page 'update'}}>
{{page.name}}
</div>
</div>
@@ -31,7 +31,7 @@
{{#each footerPages as |page|}}
<div class="row">
<div class="column">
<div role="button" class="ui segment" {{action 'updateCurrentPage' page.path}}>
<div role="button" class="ui segment" {{action 'updateCurrentPage' page 'update'}}>
{{page.name}}
</div>
</div>
@@ -40,7 +40,7 @@
</div>
<div class="column eleven wide">
{{#if isFormOpen}}
{{forms/admin/content/pages-form data=currentForm places=places}}
{{forms/admin/content/pages-form data=currentForm save='savePage' isCreate=isCreate isFormOpen=isFormOpen}}
{{/if}}
</div>
</div>
@@ -1,4 +1,4 @@
<form class="ui form" {{action 'submit' on='submit'}}>
<form class="ui form" {{action 'submit' data on='submit'}}>
<div class="field">
<label>{{t 'Name'}}</label>
{{input name='name' type='text' value=data.name}}
@@ -9,33 +9,30 @@
</div>
<div class="field">
<label>{{t 'URL'}}</label>
{{input type='text' name='url' value=data.path}}
{{input type='text' name='url' value=data.url}}
</div>
<div class="field">
<label>{{t 'Description'}}</label>
{{widgets/forms/rich-text-editor value=data.description}}
</div>
<div class="field">
<label>{{t 'Places'}}</label>
{{#ui-dropdown class='selection' selected=data.menu}}
{{input type='hidden' name='place' value=data.menu}}
<label>{{t 'Place'}}</label>
{{#ui-dropdown class='selection' selected=data.place onChange=(action (mut data.place))}}
<i class="dropdown icon"></i>
<div class="default text">{{data.menu}}</div>
<div class="default text">{{data.place}}</div>
<div class="menu">
{{#each places as |place|}}
<div class="item" data-value="{{place}}">{{place}}</div>
{{/each}}
<div class="item" data-value="event">{{t 'Event'}}</div>
<div class="item" data-value="footer">{{t 'Footer'}}</div>
</div>
{{/ui-dropdown}}
</div>
<div class="field">
<label>{{t 'Position'}}</label>
{{input type='number' name='position' value=data.position min=1}}
{{input type='number' name='position' value=data.index min=1}}
</div>
<div class="field">
<label>{{t 'Language'}}</label>
{{#ui-dropdown class='selection' selected=data.language}}
{{input type='hidden' name='language'}}
{{#ui-dropdown class='selection' selected=data.language onChange=(action (mut data.language))}}
<i class="dropdown icon"></i>
<div class="default text">{{get l10n.availableLocales data.language}}</div>
<div class="menu">
@@ -46,7 +43,11 @@
{{/ui-dropdown}}
</div>
<div class="ui buttons">
<button class="ui teal button" type="submit">{{t 'Update Page'}}</button>
<button class="ui red button">{{t 'Delete Page'}}</button>
<button class="ui teal button" type="submit">{{if isCreate 'Save' 'Update'}}</button>
{{#if isCreate}}
<button class="ui red button" {{action 'close'}}>{{t 'Cancel'}}</button>
{{else}}
<button class="ui red button" {{action (confirm (t 'Are you sure you would like to delete this page?') (action 'deletePage' data))}}>{{t 'Delete'}}</button>
{{/if}}
</div>
</form>
@@ -0,0 +1,12 @@
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('page', 'Unit | Model | page', {
// Specify the other units that are required for this test.
needs: []
});
test('it exists', function(assert) {
let model = this.subject();
// let store = this.store();
assert.ok(!!model);
});
ProTip! Use n and p to navigate between commits in a pull request.