Skip to content

Commit

Permalink
Merge pull request #57 from documize/refactor-folder-routers
Browse files Browse the repository at this point in the history
Refactor space routes
  • Loading branch information
HarveyKandola authored Nov 7, 2016
2 parents b6afd06 + acb83f2 commit cc353fb
Show file tree
Hide file tree
Showing 33 changed files with 710 additions and 778 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li

## Latest version

v0.29.0
v0.30.0

## OS Support

Expand Down
15 changes: 0 additions & 15 deletions app/app/components/back-to-home.js

This file was deleted.

16 changes: 0 additions & 16 deletions app/app/components/document/document-sidebar-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
this.destroyTooltips();
},

// positionToc() {
// let s = $(".document-structure");
// let pos = s.position();
//
// $(window).scroll(_.throttle(function() {
// let windowpos = $(window).scrollTop();
// if (windowpos - 200 >= pos.top) {
// s.addClass("stuck-toc");
// s.css('width', s.parent().width());
// } else {
// s.removeClass("stuck-toc");
// s.css('width', 'auto');
// }
// }, 50));
// },

onDocumentPageAdded(pageId) {
this.send('onEntryClick', pageId);
},
Expand Down
12 changes: 12 additions & 0 deletions app/app/components/folder/folders-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
init() {
this._super(...arguments);

if (this.get('noFolder')) {
return;
}

let _this = this;
this.get('templateService').getSavedTemplates().then(function(saved) {
let emptyTemplate = {
Expand All @@ -57,12 +61,20 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
},

didRender() {
if (this.get('noFolder')) {
return;
}

if (this.get('folderService').get('canEditCurrentFolder')) {
this.addTooltip(document.getElementById("start-document-button"));
}
},

didInsertElement() {
if (this.get('noFolder')) {
return;
}

this.eventBus.subscribe('resized', this, 'positionTool');
this.eventBus.subscribe('scrolled', this, 'positionTool');
},
Expand Down
13 changes: 9 additions & 4 deletions app/app/components/folder/start-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ export default Ember.Component.extend(NotifierMixin, {
this.setupImport();
},

willDestroyElement() {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
},

setupImport() {
// already done init?
if (is.not.null(this.get('drop'))) {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
this.get('drop').destroy();
this.set('drop', null);
}

let self = this;
Expand Down
14 changes: 0 additions & 14 deletions app/app/components/layout/zone-container.js

This file was deleted.

8 changes: 4 additions & 4 deletions app/app/pods/auth/login/controller.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
// by contacting <sales@documize.com>.
//
// https://documize.com

Expand Down Expand Up @@ -38,11 +38,11 @@ export default Ember.Controller.extend({
this.get('session').authenticate('authenticator:documize', creds)
.then((response) => {
this.get('audit').record("logged-in");
this.transitionToRoute('folders.folder');
this.transitionToRoute('folders');
return response;
}).catch(() => {
this.set('invalidCredentials', true);
});
}
}
});
});
12 changes: 8 additions & 4 deletions app/app/pods/auth/logout/route.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
// by contacting <sales@documize.com>.
//
// https://documize.com

Expand All @@ -24,7 +24,11 @@ export default Ember.Route.extend({
if (config.environment === 'test') {
this.transitionTo('auth.login');
} else {
window.document.location = this.get("appMeta.allowAnonymousAccess") ? "/" : "/auth/login";
if (this.get("appMeta.allowAnonymousAccess")) {
this.transitionTo('folders');
} else {
this.transitionTo('auth.login');
}
}
}
});
});
7 changes: 4 additions & 3 deletions app/app/pods/auth/route.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
// by contacting <sales@documize.com>.
//
// https://documize.com

import Ember from 'ember';

export default Ember.Route.extend({});
export default Ember.Route.extend({
});
8 changes: 4 additions & 4 deletions app/app/pods/auth/sso/route.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
// by contacting <sales@documize.com>.
//
// https://documize.com

Expand All @@ -17,10 +17,10 @@ export default Ember.Route.extend({
model({ token }) {
this.get("session").authenticate('authenticator:documize', decodeURIComponent(token))
.then(() => {
this.transitionTo('folders.folder');
this.transitionTo('folders');
}, () => {
this.transitionTo('auth.login');
console.log(">>>>> Documize SSO failure");
});
},
});
});
2 changes: 1 addition & 1 deletion app/app/pods/customize/folders/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{{#each folders as |folder|}}
<tr>
<td class="bordered">
{{#link-to 'folders.folder' folder.id folder.slug class="alt"}}{{folder.name}}{{/link-to}}
{{#link-to 'folder' folder.id folder.slug class="alt"}}{{folder.name}}{{/link-to}}
</td>
<td class="bordered">
{{#each folder.sharedWith as |person|}}
Expand Down
2 changes: 1 addition & 1 deletion app/app/pods/document/index/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export default Ember.Controller.extend(NotifierMixin, {
this.get('documentService').deleteDocument(this.get('model.id')).then(function () {
self.audit.record("deleted-page");
self.send("showNotification", "Deleted");
self.transitionToRoute('folders.folder', self.get('folder.id'), self.get('folder.slug'));
self.transitionToRoute('folder', self.get('folder.id'), self.get('folder.slug'));
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// https://documize.com

import Ember from 'ember';
import NotifierMixin from '../../../mixins/notifier';
import NotifierMixin from '../../mixins/notifier';

export default Ember.Controller.extend(NotifierMixin, {
documentService: Ember.inject.service('document'),
Expand Down Expand Up @@ -71,7 +71,7 @@ export default Ember.Controller.extend(NotifierMixin, {

this.get('folderService').add({ name: folder }).then(function (newFolder) {
self.get('folderService').setCurrentFolder(newFolder);
self.transitionToRoute('folders.folder', newFolder.get('id'), newFolder.get('slug'));
self.transitionToRoute('folder', newFolder.get('id'), newFolder.get('slug'));
});
}
}
Expand Down
File renamed without changes.
File renamed without changes.
21 changes: 18 additions & 3 deletions app/app/pods/folders/controller.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// This software (Documize Community Edition) is licensed under
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
//
// You can operate outside the AGPL restrictions by purchasing
// Documize Enterprise Edition and obtaining a commercial license
// by contacting <sales@documize.com>.
// by contacting <sales@documize.com>.
//
// https://documize.com

import Ember from 'ember';
import NotifierMixin from '../../mixins/notifier';

export default Ember.Controller.extend({});
export default Ember.Controller.extend(NotifierMixin, {
folderService: Ember.inject.service('folder'),

actions: {
onFolderAdd(folder) {
let self = this;
this.showNotification("Added");

this.get('folderService').add({ name: folder }).then(function (newFolder) {
self.get('folderService').setCurrentFolder(newFolder);
self.transitionToRoute('folder', newFolder.get('id'), newFolder.get('slug'));
});
}
}
});
63 changes: 0 additions & 63 deletions app/app/pods/folders/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,11 @@

import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import { isNotFoundError } from 'ember-ajax/errors';

const {
isPresent
} = Ember;

export default Ember.Route.extend(AuthenticatedRouteMixin, {
folderService: Ember.inject.service('folder'),
localStorage: Ember.inject.service(),
folder: {},

model: function () {
return this.get('folderService').getAll();
},

afterModel: function (model) {
let params = this.paramsFor('folders.folder');

if (is.empty(params)) {
let lastFolder = this.get('localStorage').getSessionItem("folder");
let self = this;

//If folder lastFolder is defined
if (isPresent(lastFolder)) {
return this.get('folderService').getFolder(lastFolder).then((folder) => {
//if Response is null or undefined redirect to login else transitionTo dashboard
if (Ember.isNone(folder)) {
self.get('localStorage').clearSessionItem("folder");
this.transitionTo('application');
}

Ember.set(this, 'folder', folder);
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
}).catch(() => {
//if there was an error redirect to login
self.get('localStorage').clearSessionItem("folder");
this.transitionTo('application');
});
}

// If model has any folders redirect to dashboard
if (model.get('length') > 0) {
let folder = model[0];
Ember.set(this, 'folder', folder);
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
}
}

//If folder route has params
if (isPresent(params)) {
let self = this;
let folderId = this.paramsFor('folders.folder').folder_id;

return this.get('folderService').getFolder(folderId).then((folder) => {
Ember.set(this, 'folder', folder);
}).catch(function (error) {
if (isNotFoundError(error)) {
// handle 404 errors here
self.transitionTo('application');
}
});
}

this.browser.setMetaDescription();
},

setupController(controller, model) {
controller.set('model', model);
controller.set('folder', this.folder);
}
});
9 changes: 8 additions & 1 deletion app/app/pods/folders/template.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{{outlet}}
{{layout/zone-navigation}}

{{#layout/zone-sidebar}}
{{folder/folders-list folders=model noFolder=true onFolderAdd=(action 'onFolderAdd')}}
{{/layout/zone-sidebar}}

{{#layout/zone-content}}
{{/layout/zone-content}}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// https://documize.com

import Ember from 'ember';
import NotifierMixin from '../../../mixins/notifier';
import NotifierMixin from '../../mixins/notifier';

const {
inject: { service }
Expand Down Expand Up @@ -119,7 +119,7 @@ export default Ember.Route.extend(NotifierMixin, {

this.get('folderService').getFolder(moveId).then((folder) => {
this.get('folderService').setCurrentFolder(folder);
this.transitionTo('folders.folder', folder.get('id'), folder.get('slug'));
this.transitionTo('folder', folder.get('id'), folder.get('slug'));
});
});
},
Expand Down
Loading

0 comments on commit cc353fb

Please sign in to comment.