Skip to content

Commit

Permalink
Add dynamic pages that can be created from the backend (#96)
Browse files Browse the repository at this point in the history
* Add modular pages to the website
  • Loading branch information
fromHearts authored Dec 29, 2021
1 parent f4958ea commit d5597f5
Show file tree
Hide file tree
Showing 34 changed files with 1,483 additions and 1,350 deletions.
23 changes: 0 additions & 23 deletions app/components/header-nav.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { inject as service } from '@ember/service';

export default Component.extend({
session: service(),
settings: service(),
init() {
this._super(...arguments);
this.menuItems = [
Expand Down Expand Up @@ -46,27 +44,6 @@ export default Component.extend({
}
];
},
getMenuItems: computed('menuItems', 'settings.settings.design_presentation_pages_enabled', function() {

// const enabled = this.get('settings.settings.design_presentation_pages_enabled');
// /*
// * The page is only visible when authenticated
// */
// if (this.get('session.isAuthenticated')) {
// //

// all routes are visible when logged in
if (this.get('session.isAuthenticated')) {
return this.menuItems;
}

// Filter join and design presentation pages if needed.
let items = this.menuItems;
if (!this.get('settings.settings.design_presentation_pages_enabled')) {
items = items.filter(item => item.link !== 'design-presentation');
}
return items;
}),
showMobileMenu: false,
actions: {
toggleMobileMenu() {
Expand Down
28 changes: 28 additions & 0 deletions app/controllers/admin/page-item/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Controller from '@ember/controller';
import saveModelMixin from "roboteam-website/mixins/save-model"
import { computed } from '@ember/object'

export default Controller.extend(saveModelMixin, {
init() {
this._super(...arguments);
this.requiredProperties = ["title", "content", "page"];
},
noticeDuringSave: "Updating page item...",
noticeAfterSave: "Page item updated!",
modelName: "model",
transitionAfterSuccess: "admin.page-item",
transitionToIndexRoute: true,
imagePath: "images/page/items",
allPages: computed(function() {
return this.store.findAll('page');
}),
actions: {
customSave: function() {
if (this.get('file') || this.get('model.imageSrc')) {
this.send('saveModelWithImage');
} else {
this.send('saveModel');
}
}
}
});
8 changes: 8 additions & 0 deletions app/controllers/admin/page-item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Controller from '@ember/controller';
import removeModelAction from 'roboteam-website/mixins/remove-model-action';
import changeOrder from 'roboteam-website/mixins/change-order';

export default Controller.extend(removeModelAction, changeOrder, {
modelType: "pageitem",
modelNameProperty: "title",
});
3 changes: 3 additions & 0 deletions app/controllers/admin/page-item/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import EditController from "roboteam-website/controllers/admin/page-item/edit";

export default EditController.extend({ });
15 changes: 15 additions & 0 deletions app/controllers/admin/page/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Controller from '@ember/controller';
import saveModelMixin from "roboteam-website/mixins/save-model"

export default Controller.extend(saveModelMixin, {
init() {
this._super(...arguments);
this.requiredProperties = ["name", "description"];
},
noticeDuringSave: "Updating page...",
noticeAfterSave: "Page updated!",
modelName: "model",
transitionAfterSuccess: "admin.page",
transitionToIndexRoute: true,
imagePath: "images/page",
});
8 changes: 8 additions & 0 deletions app/controllers/admin/page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Controller from '@ember/controller';
import removeModelAction from 'roboteam-website/mixins/remove-model-action';
import changeOrder from 'roboteam-website/mixins/change-order';

export default Controller.extend(removeModelAction, changeOrder, {
modelType: "page",
modelNameProperty: "name",
});
3 changes: 3 additions & 0 deletions app/controllers/admin/page/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import EditController from "roboteam-website/controllers/admin/page/edit";

export default EditController.extend({ });
2 changes: 1 addition & 1 deletion app/controllers/admin/subteams/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export default Controller.extend(saveModelMixin, {
transitionAfterSuccess: "admin.subteams",
transitionToIndexRoute: true,
imagePath: "images/subteams",
});
});
6 changes: 6 additions & 0 deletions app/controllers/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';

export default Controller.extend({
settings: service(),
});
19 changes: 19 additions & 0 deletions app/models/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import DS from 'ember-data';

const { attr, Model } = DS;
import { computed } from '@ember/object';

export default Model.extend({
createdAt: attr('date'),
updatedAt: attr('date'),
name: attr('string'),
imageSrc: attr('string'),
description: attr('string'),
order: attr('number'),

namedId: computed('name', function() {
if (!this.get('name')) return '';
const trimmed = this.get('name').trim();
return trimmed.toLowerCase().replace(' ', '_');
}),
});
45 changes: 45 additions & 0 deletions app/models/pageitem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import DS from 'ember-data';

const { attr, Model } = DS;
import { computed } from '@ember/object'

export default Model.extend({
title: attr('string'),
content: attr('string'),
imageSrc: attr('string'),
videoSrc: attr('string'),
page: attr('string'),
order: attr('number'),
createdAt: attr('date'),
updatedAt: attr('date'),

vimeoId: computed('videoSrc', function() {
const src = this.get('videoSrc');
if (!src) return src;
if (src.startsWith('https://vimeo.com/')) {
return src.replace('https://vimeo.com/', '');
}

if (src.startsWith('http://vimeo.com/')) {
return src.replace('http://vimeo.com/', '');
}

if (src.startsWith('vimeo.com/')) {
return src.replace('vimeo.com/', '');
}

return src.replace(/\D/g, '');
}),

showVideo: computed('vimeoId', function() {
return this.get('vimeoId') && this.get('vimeoId') !== "";
}),

showImage: computed('imageSrc', function() {
return this.get('imageSrc') && this.get('imageSrc') !== "";
}),

fullwidth: computed('showVideo', 'showImage', function() {
return !this.get('showVideo') && !this.get('showImage');
})
});
15 changes: 14 additions & 1 deletion app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Router.map(function() {
this.route('login')
this.route('previousteams')


this.route('news', function() {
this.route('show', { path: '/:article_id' });
});
Expand Down Expand Up @@ -88,9 +87,23 @@ Router.map(function() {
this.route('edit', { path: 'edit/:subteam_id' });
this.route('new');
});

this.route('page', function() {
this.route('edit', { path: 'edit/:page_id' });
this.route('new');
});

this.route('page-item', function() {
this.route('edit', { path: 'edit/:pageitem_id' });
this.route('new');
});
});

this.route('newsletter');

this.route('404', { path: '/404' });

this.route('page', { path: ':namedId' });

this.route('404', { path: '/*path' });
});
7 changes: 7 additions & 0 deletions app/routes/admin/page-item/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import EditRoute from 'roboteam-website/routes/base/edit';

export default EditRoute.extend({
modelName: "pageitem",
modelRouteParam: "pageitem_id",
useVideo: false,
});
5 changes: 5 additions & 0 deletions app/routes/admin/page-item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import IndexRoute from 'roboteam-website/routes/base/index';

export default IndexRoute.extend({
modelName: "pageitem"
});
5 changes: 5 additions & 0 deletions app/routes/admin/page-item/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import NewRoute from 'roboteam-website/routes/base/new';

export default NewRoute.extend({
modelName: "pageitem",
});
6 changes: 6 additions & 0 deletions app/routes/admin/page/edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import EditRoute from 'roboteam-website/routes/base/edit';

export default EditRoute.extend({
modelName: "page",
modelRouteParam: "page_id"
});
5 changes: 5 additions & 0 deletions app/routes/admin/page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import IndexRoute from 'roboteam-website/routes/base/index';

export default IndexRoute.extend({
modelName: "page"
});
5 changes: 5 additions & 0 deletions app/routes/admin/page/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import NewRoute from 'roboteam-website/routes/base/new';

export default NewRoute.extend({
modelName: "page"
});
2 changes: 1 addition & 1 deletion app/routes/news/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { ShowRouteUnauthenticated } from 'roboteam-website/routes/base/show';
export default ShowRouteUnauthenticated.extend({
modelName: "article",
modelRouteParam: "article_id"
});
});
24 changes: 24 additions & 0 deletions app/routes/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ShowRouteUnauthenticated } from 'roboteam-website/routes/base/show';
import { hash } from 'rsvp';

export default ShowRouteUnauthenticated.extend({
modelName: "page",
modelRouteParam: "name",
model(params) {
return this.store.query("page", { reload: true }).then(pages => {
const page = pages.filter(page => page.namedId === params["namedId"])[0];
if (page === undefined) {
return this.transitionTo('/404');
}
return this.store.query('pageitem', { orderBy: 'order', reload: true }).then(pageItems => {
pageItems = pageItems.filter(item => item.page === page.namedId);
return hash({
page,
pageItems,
params,
pages
});
});
});
}
});
2 changes: 1 addition & 1 deletion app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
@import 'news';
@import '404';
@import 'design-presentation';

@import 'page';
33 changes: 33 additions & 0 deletions app/styles/page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.page-header {
height: 360px;
}

.page-header-gradient {
position: absolute;
background: linear-gradient(to bottom, rgba(0,0,0,0) 0%,rgba(0,0,0,0.7) 100%);
height: 360px;
width: 100%;
}

.page-header-image {
position: absolute;
width: 100%;
height: 360px;
object-fit: cover;
background-position: center;
z-index:-1;
background: #000;
}

.vimeo-container {
padding:56.25% 0 0 0;
position:relative;

.vimeo-video {
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
}
}
10 changes: 9 additions & 1 deletion app/templates/admin.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@
<li class="list-group-item">
{{#link-to "admin.subteams"}} [Design Presentation] Subteams {{/link-to}}
</li>

<li class="list-group-item">
{{#link-to "admin.page"}} Pages {{/link-to}}
</li>

<li class="list-group-item">
{{#link-to "admin.page-item"}} Page items {{/link-to}}
</li>
</ul>
</div>

<div class="col-12 col-md-9">
{{outlet}}
</div>
</div>
</div>
</div>
1 change: 1 addition & 0 deletions app/templates/admin/page-item/edit.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{partial "admin/page-item/form"}}
Loading

0 comments on commit d5597f5

Please sign in to comment.