Skip to content

Commit

Permalink
Merge pull request #52 from documize/content-links
Browse files Browse the repository at this point in the history
Content links
  • Loading branch information
HarveyKandola authored Oct 29, 2016
2 parents 9b5b94f + eb0295b commit aad1ffb
Show file tree
Hide file tree
Showing 54 changed files with 2,489 additions and 977 deletions.
94 changes: 47 additions & 47 deletions app/.jshintrc
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"predef": [
"server",
"document",
"window",
"-Promise",
"moment",
"$",
"_",
"is",
"Mousetrap",
"CodeMirror",
"Intercom",
"Materialize",
"tinymce",
"Tether",
"Tooltip",
"Drop",
"Dropzone",
"dragula",
"datetimepicker",
"Waypoint"
],
"browser": true,
"boss": true,
"curly": true,
"debug": false,
"devel": true,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"eqnull": true,
"esnext": true,
"unused": true
"predef": [
"server",
"document",
"window",
"-Promise",
"moment",
"$",
"_",
"is",
"Mousetrap",
"CodeMirror",
"Intercom",
"Materialize",
"tinymce",
"Tether",
"Tooltip",
"Drop",
"Dropzone",
"dragula",
"datetimepicker",
"Waypoint"
],
"browser": true,
"boss": true,
"curly": true,
"debug": false,
"devel": true,
"eqeqeq": true,
"evil": true,
"forin": false,
"immed": false,
"laxbreak": false,
"newcap": true,
"noarg": true,
"noempty": false,
"nonew": false,
"nomen": false,
"onevar": false,
"plusplus": false,
"regexp": false,
"undef": true,
"sub": true,
"strict": false,
"white": false,
"eqnull": true,
"esnext": true,
"unused": true
}
38 changes: 38 additions & 0 deletions app/app/components/document/document-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
documentService: Ember.inject.service('document'),
sectionService: Ember.inject.service('section'),
appMeta: Ember.inject.service(),
link: Ember.inject.service(),
/* Parameters */
document: null,
// pages: [],
Expand Down Expand Up @@ -50,6 +51,10 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
});
},

didRender() {
this.contentLinkHandler();
},

willDestroyElement() {
this.destroyTooltips();

Expand All @@ -60,6 +65,39 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
}
},

contentLinkHandler() {
let links = this.get('link');
let doc = this.get('document');
let self = this;

$("a[data-documize='true']").off('click').on('click', function(e) {
let link = links.getLinkObject(self.get('meta.outboundLinks'), this);

// local link? exists?
if (link.linkType === "section" && link.documentId === doc.get('id')) {
let exists = self.get('pages').findBy('id', link.targetId);

if (_.isUndefined(exists)) {
link.orphan = true;
} else {
self.attrs.gotoPage(link.targetId);
return false;
}
}

if (link.orphan) {
$(this).addClass('broken-link');
self.showNotification('Broken link!');
e.preventDefault();
e.stopPropagation();
return false;
}

links.linkClick(doc, link);
return false;
});
},

actions: {
confirmDeleteAttachment(id, name) {
this.set('deleteAttachment', {
Expand Down
133 changes: 133 additions & 0 deletions app/app/components/document/edit-tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
// 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 TooltipMixin from '../../mixins/tooltip';

const {
inject: { service }
} = Ember;

export default Ember.Component.extend(TooltipMixin, {
link: service(),
linkName: '',
keywords: '',
selection: null,
matches: {
documents: [],
pages: [],
attachments: []
},
tabs: [
{ label: 'Section', selected: true },
{ label: 'Attachment', selected: false },
{ label: 'Search', selected: false }
],

showSections: Ember.computed('tabs.@each.selected', function () {
return this.get('tabs').findBy('label', 'Section').selected;
}),
showAttachments: Ember.computed('tabs.@each.selected', function () {
return this.get('tabs').findBy('label', 'Attachment').selected;
}),
showSearch: Ember.computed('tabs.@each.selected', function () {
return this.get('tabs').findBy('label', 'Search').selected;
}),
hasMatches: Ember.computed('matches', function () {
let m = this.get('matches');
return m.documents.length || m.pages.length || m.attachments.length;
}),

init() {
this._super(...arguments);
let self = this;

let folderId = this.get('folder.id');
let documentId = this.get('document.id');
let pageId = this.get('page.id');

this.get('link').getCandidates(folderId, documentId, pageId).then(function (candidates) {
self.set('candidates', candidates);
self.set('hasSections', is.not.null(candidates.pages) && candidates.pages.length);
self.set('hasAttachments', is.not.null(candidates.attachments) && candidates.attachments.length);
});
},

didRender() {
this.addTooltip(document.getElementById("content-linker-button"));
this.addTooltip(document.getElementById("content-counter-button"));
},

willDestroyElement() {
this.destroyTooltips();
},

onKeywordChange: function () {
Ember.run.debounce(this, this.fetch, 750);
}.observes('keywords'),

fetch() {
let keywords = this.get('keywords');
let self = this;

if (_.isEmpty(keywords)) {
this.set('matches', { documents: [], pages: [], attachments: [] });
return;
}

this.get('link').searchCandidates(keywords).then(function (matches) {
self.set('matches', matches);
});
},

actions: {
setSelection(i) {
let candidates = this.get('candidates');
let matches = this.get('matches');

this.set('selection', i);

candidates.pages.forEach(c => {
Ember.set(c, 'selected', c.id === i.id);
});

candidates.attachments.forEach(c => {
Ember.set(c, 'selected', c.id === i.id);
});

matches.documents.forEach(c => {
Ember.set(c, 'selected', c.id === i.id);
});

matches.pages.forEach(c => {
Ember.set(c, 'selected', c.id === i.id);
});

matches.attachments.forEach(c => {
Ember.set(c, 'selected', c.id === i.id);
});
},

onInsertLink() {
let selection = this.get('selection');

if (is.null(selection)) {
return;
}

return this.get('onInsertLink')(selection);
},

onTabSelect(tabs) {
this.set('tabs', tabs);
}
}
});
Loading

0 comments on commit aad1ffb

Please sign in to comment.