1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00
documize/gui/app/components/layout/zone-navigation.js

164 lines
4.4 KiB
JavaScript
Raw Normal View History

2016-07-07 18:54:16 -07:00
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// 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>.
//
// https://documize.com
import Ember from 'ember';
import netUtil from '../../utils/net';
import constants from '../../utils/constants';
2016-11-05 16:02:35 -07:00
import TooltipMixin from '../../mixins/tooltip';
2016-07-07 18:54:16 -07:00
const {
inject: { service }
} = Ember;
2016-11-05 16:02:35 -07:00
export default Ember.Component.extend(TooltipMixin, {
2016-08-29 21:34:35 +02:00
folderService: service('folder'),
appMeta: service(),
session: service(),
2016-11-21 19:27:18 -08:00
store: service(),
folder: null,
2016-11-04 15:33:56 -07:00
view: {
2016-11-05 14:53:44 -07:00
folder: false,
2016-11-04 15:33:56 -07:00
search: false,
settings: false,
profile: false
},
2016-11-21 19:27:18 -08:00
pinned: service(),
pins: [],
enableLogout: true,
2016-07-07 18:54:16 -07:00
2016-10-04 15:24:21 -07:00
init() {
this._super(...arguments);
2016-11-04 15:33:56 -07:00
if (this.get("session.authenticated") && this.get("session.user.id") !== '0') {
2017-04-16 15:47:39 +01:00
this.get("session.accounts").forEach((account) => {
// TODO: do not mutate account.active here
account.active = account.orgId === this.get("appMeta.orgId");
});
2016-07-07 18:54:16 -07:00
}
2016-11-21 19:27:18 -08:00
this.set('pins', this.get('pinned').get('pins'));
if (this.get('appMeta.authProvider') === constants.AuthProvider.Keycloak) {
let config = this.get('appMeta.authConfig');
config = JSON.parse(config);
this.set('enableLogout', !config.disableLogout);
}
2016-07-07 18:54:16 -07:00
},
didReceiveAttrs() {
if (this.get('folder') === null) {
this.set("folder", this.get('folderService.currentFolder'));
}
2016-11-04 15:33:56 -07:00
let route = this.get('router.currentRouteName');
2016-11-05 14:53:44 -07:00
this.set('view.folder', (is.startWith(route, 'folder')) ? true : false);
this.set('view.settings', (is.startWith(route, 'customize')) ? true : false);
2016-11-04 15:33:56 -07:00
this.set('view.profile', (route === 'profile') ? true : false);
this.set('view.search', (route === 'search') ? true : false);
2016-07-07 18:54:16 -07:00
},
2016-11-21 19:27:18 -08:00
didInsertElement() {
this._super(...arguments);
// Size the pinned items zone
if (this.get("session.authenticated")) {
this.eventBus.subscribe('resized', this, 'sizePinnedZone');
this.eventBus.subscribe('pinChange', this, 'setupPins');
this.sizePinnedZone();
this.setupPins();
let self = this;
var sortable = Sortable.create(document.getElementById('pinned-zone'), {
animation: 150,
onEnd: function () {
self.get('pinned').updateSequence(this.toArray()).then((pins) => {
self.set('pins', pins);
});
}
2016-11-21 19:27:18 -08:00
});
this.set('sortable', sortable);
}
},
2016-11-05 16:02:35 -07:00
didRender() {
if (this.get('session.isAdmin')) {
this.addTooltip(document.getElementById("workspace-settings"));
}
if (this.get("session.authenticated") && this.get('enableLogout')) {
2016-11-05 16:02:35 -07:00
this.addTooltip(document.getElementById("workspace-logout"));
} else {
this.addTooltip(document.getElementById("workspace-login"));
}
},
2016-11-21 19:27:18 -08:00
setupPins() {
if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
2016-11-21 19:27:18 -08:00
this.get('pinned').getUserPins().then((pins) => {
if (this.get('isDestroyed') || this.get('isDestroying')) {
return;
}
2016-11-21 19:27:18 -08:00
this.set('pins', pins);
pins.forEach((pin) => {
this.addTooltip(document.getElementById(`pin-${pin.id}`));
});
});
},
// set height for pinned zone so ti scrolls on spill
sizePinnedZone() {
let topofBottomZone = parseInt($('#bottom-zone').css("top").replace("px", ""));
let heightOfTopZone = parseInt($('#top-zone').css("height").replace("px", ""));
let size = topofBottomZone - heightOfTopZone - 40;
$('#pinned-zone').css('height', size + "px");
},
willDestroyElement() {
let sortable = this.get('sortable');
if (!_.isUndefined(sortable)) {
sortable.destroy();
}
this.eventBus.unsubscribe('resized');
this.eventBus.unsubscribe('pinChange');
2016-11-21 19:27:18 -08:00
this.destroyTooltips();
},
2016-07-07 18:54:16 -07:00
actions: {
switchAccount(domain) {
window.location.href = netUtil.getAppUrl(domain);
2016-11-21 19:27:18 -08:00
},
jumpToPin(pin) {
let folderId = pin.get('folderId');
let documentId = pin.get('documentId');
if (_.isEmpty(documentId)) {
// jump to space
let folder = this.get('store').peekRecord('folder', folderId);
this.get('router').transitionTo('folder', folderId, folder.get('slug'));
} else {
// jump to doc
let folder = this.get('store').peekRecord('folder', folderId);
this.get('router').transitionTo('document', folderId, folder.get('slug'), documentId, 'document');
}
2016-07-07 18:54:16 -07:00
}
}
});