mirror of
https://github.com/documize/community.git
synced 2025-07-21 14:19:43 +02:00
per space templates
This commit is contained in:
parent
574139ae21
commit
558d90d2ba
10 changed files with 73 additions and 36 deletions
|
@ -229,12 +229,12 @@ func processDocument(ctx domain.RequestContext, store *domain.Store, filename, j
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = store.Document.Update(ctx, newDocument) // TODO review - this seems to write-back an unaltered record from that read above, but within that it calls searches.UpdateDocument() to reindex the doc.
|
// err = store.Document.Update(ctx, newDocument) // TODO review - this seems to write-back an unaltered record from that read above, but within that it calls searches.UpdateDocument() to reindex the doc.
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
// ctx.Transaction.Rollback()
|
||||||
err = errors.Wrap(err, "cannot updater new document")
|
// err = errors.Wrap(err, "cannot updater new document")
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: newDocument.LabelID,
|
LabelID: newDocument.LabelID,
|
||||||
|
|
|
@ -157,7 +157,7 @@ func (s Scope) GetByTag(ctx domain.RequestContext, tag string) (documents []doc.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Templates returns a slice containing the documents available as templates to the client's organisation, in title order.
|
// Templates returns a slice containing the documents available as templates to the client's organisation, in title order.
|
||||||
func (s Scope) Templates(ctx domain.RequestContext) ( documents []doc.Document, err error) {
|
func (s Scope) Templates(ctx domain.RequestContext) (documents []doc.Document, err error) {
|
||||||
err = s.Runtime.Db.Select(&documents,
|
err = s.Runtime.Db.Select(&documents,
|
||||||
`SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised FROM document WHERE orgid=? AND template=1 AND labelid IN
|
`SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised FROM document WHERE orgid=? AND template=1 AND labelid IN
|
||||||
(SELECT refid from label WHERE orgid=? AND type=2 AND userid=?
|
(SELECT refid from label WHERE orgid=? AND type=2 AND userid=?
|
||||||
|
@ -174,7 +174,33 @@ func (s Scope) Templates(ctx domain.RequestContext) ( documents []doc.Document,
|
||||||
ctx.UserID)
|
ctx.UserID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "select documents templates")
|
err = errors.Wrap(err, "select document templates")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// TemplatesBySpace returns a slice containing the documents available as templates for given space.
|
||||||
|
func (s Scope) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (documents []doc.Document, err error) {
|
||||||
|
err = s.Runtime.Db.Select(&documents,
|
||||||
|
`SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised FROM document WHERE orgid=? AND labelid=? AND template=1 AND labelid IN
|
||||||
|
(SELECT refid from label WHERE orgid=? AND type=2 AND userid=?
|
||||||
|
UNION ALL SELECT refid FROM label a where orgid=? AND type=1 AND refid IN (SELECT labelid from labelrole WHERE orgid=? AND userid='' AND (canedit=1 OR canview=1))
|
||||||
|
UNION ALL SELECT refid FROM label a where orgid=? AND type=3 AND refid IN (SELECT labelid from labelrole WHERE orgid=? AND userid=? AND (canedit=1 OR canview=1)))
|
||||||
|
ORDER BY title`,
|
||||||
|
ctx.OrgID,
|
||||||
|
spaceID,
|
||||||
|
ctx.OrgID,
|
||||||
|
ctx.UserID,
|
||||||
|
ctx.OrgID,
|
||||||
|
ctx.OrgID,
|
||||||
|
ctx.OrgID,
|
||||||
|
ctx.OrgID,
|
||||||
|
ctx.UserID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
err = errors.Wrap(err, "select space document templates")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,7 @@ type DocumentStorer interface {
|
||||||
GetByTag(ctx RequestContext, tag string) (documents []doc.Document, err error)
|
GetByTag(ctx RequestContext, tag string) (documents []doc.Document, err error)
|
||||||
DocumentList(ctx RequestContext) (documents []doc.Document, err error)
|
DocumentList(ctx RequestContext) (documents []doc.Document, err error)
|
||||||
Templates(ctx RequestContext) (documents []doc.Document, err error)
|
Templates(ctx RequestContext) (documents []doc.Document, err error)
|
||||||
|
TemplatesBySpace(ctx RequestContext, spaceID string) (documents []doc.Document, err error)
|
||||||
DocumentMeta(ctx RequestContext, id string) (meta doc.DocumentMeta, err error)
|
DocumentMeta(ctx RequestContext, id string) (meta doc.DocumentMeta, err error)
|
||||||
PublicDocuments(ctx RequestContext, orgID string) (documents []doc.SitemapDocument, err error)
|
PublicDocuments(ctx RequestContext, orgID string) (documents []doc.SitemapDocument, err error)
|
||||||
Update(ctx RequestContext, document doc.Document) (err error)
|
Update(ctx RequestContext, document doc.Document) (err error)
|
||||||
|
|
|
@ -49,7 +49,13 @@ func (h *Handler) SavedList(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "template.saved"
|
method := "template.saved"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
documents, err := h.Store.Document.Templates(ctx)
|
folderID := request.Param(r, "folderID")
|
||||||
|
if len(folderID) == 0 {
|
||||||
|
response.WriteMissingDataError(w, method, "folderID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
documents, err := h.Store.Document.TemplatesBySpace(ctx, folderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
|
@ -67,7 +73,9 @@ func (h *Handler) SavedList(w http.ResponseWriter, r *http.Request) {
|
||||||
t.Dated = d.Created
|
t.Dated = d.Created
|
||||||
t.Type = template.TypePrivate
|
t.Type = template.TypePrivate
|
||||||
|
|
||||||
templates = append(templates, t)
|
if d.LabelID == folderID {
|
||||||
|
templates = append(templates, t)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.WriteJSON(w, templates)
|
response.WriteJSON(w, templates)
|
||||||
|
|
|
@ -12,14 +12,13 @@
|
||||||
import Ember from 'ember';
|
import Ember from 'ember';
|
||||||
import NotifierMixin from '../../mixins/notifier';
|
import NotifierMixin from '../../mixins/notifier';
|
||||||
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
computed,
|
computed,
|
||||||
} = Ember;
|
} = Ember;
|
||||||
|
|
||||||
export default Ember.Component.extend(NotifierMixin, {
|
export default Ember.Component.extend(NotifierMixin, {
|
||||||
localStorage: Ember.inject.service(),
|
localStorage: Ember.inject.service(),
|
||||||
appMeta: Ember.inject.service(),
|
appMeta: Ember.inject.service(),
|
||||||
templateService: Ember.inject.service('template'),
|
|
||||||
canEditTemplate: "",
|
canEditTemplate: "",
|
||||||
importedDocuments: [],
|
importedDocuments: [],
|
||||||
savedTemplates: [],
|
savedTemplates: [],
|
||||||
|
@ -27,27 +26,14 @@ export default Ember.Component.extend(NotifierMixin, {
|
||||||
newDocumentName: 'New Document',
|
newDocumentName: 'New Document',
|
||||||
newDocumentNameMissing: computed.empty('newDocumentName'),
|
newDocumentNameMissing: computed.empty('newDocumentName'),
|
||||||
|
|
||||||
init() {
|
|
||||||
this._super(...arguments);
|
|
||||||
|
|
||||||
this.get('templateService').getSavedTemplates().then((saved) => {
|
|
||||||
let emptyTemplate = {
|
|
||||||
id: "0",
|
|
||||||
title: "Empty",
|
|
||||||
description: "An empty canvas for your words",
|
|
||||||
layout: "doc",
|
|
||||||
locked: true
|
|
||||||
};
|
|
||||||
|
|
||||||
saved.unshiftObject(emptyTemplate);
|
|
||||||
this.set('savedTemplates', saved);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
this.setupImport();
|
this.setupImport();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
didReceiveAttrs() {
|
||||||
|
this.setupTemplates();
|
||||||
|
},
|
||||||
|
|
||||||
willDestroyElement() {
|
willDestroyElement() {
|
||||||
if (is.not.null(this.get('drop'))) {
|
if (is.not.null(this.get('drop'))) {
|
||||||
this.get('drop').destroy();
|
this.get('drop').destroy();
|
||||||
|
@ -55,6 +41,21 @@ export default Ember.Component.extend(NotifierMixin, {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setupTemplates() {
|
||||||
|
let templates = this.get('templates');
|
||||||
|
|
||||||
|
let emptyTemplate = {
|
||||||
|
id: "0",
|
||||||
|
title: "Empty",
|
||||||
|
description: "An empty canvas for your words",
|
||||||
|
layout: "doc",
|
||||||
|
locked: true
|
||||||
|
};
|
||||||
|
|
||||||
|
templates.unshiftObject(emptyTemplate);
|
||||||
|
this.set('savedTemplates', templates);
|
||||||
|
},
|
||||||
|
|
||||||
setupImport() {
|
setupImport() {
|
||||||
// already done init?
|
// already done init?
|
||||||
if (is.not.null(this.get('drop'))) {
|
if (is.not.null(this.get('drop'))) {
|
||||||
|
@ -151,4 +152,3 @@ export default Ember.Component.extend(NotifierMixin, {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout
|
||||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||||
documentService: Ember.inject.service('document'),
|
documentService: Ember.inject.service('document'),
|
||||||
folderService: Ember.inject.service('folder'),
|
folderService: Ember.inject.service('folder'),
|
||||||
|
templateService: Ember.inject.service('template'),
|
||||||
session: Ember.inject.service(''),
|
session: Ember.inject.service(''),
|
||||||
folder: {},
|
folder: {},
|
||||||
|
|
||||||
|
@ -41,7 +42,8 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
||||||
isEditor: this.get('isEditor'),
|
isEditor: this.get('isEditor'),
|
||||||
isFolderOwner: this.get('isFolderOwner'),
|
isFolderOwner: this.get('isFolderOwner'),
|
||||||
folders: this.get('folderService').getAll(),
|
folders: this.get('folderService').getAll(),
|
||||||
documents: this.get('documentService').getAllByFolder(params.folder_id)
|
documents: this.get('documentService').getAllByFolder(params.folder_id),
|
||||||
|
templates: this.get('templateService').getSavedTemplates(params.folder_id)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{{folder/folder-heading folder=model.folder isFolderOwner=model.isFolderOwner isEditor=model.isEditor}}
|
{{folder/folder-heading folder=model.folder isFolderOwner=model.isFolderOwner isEditor=model.isEditor}}
|
||||||
{{folder/folder-toolbar folders=model.folders folder=model.folder hasSelectedDocuments=hasSelectedDocuments
|
{{folder/folder-toolbar folders=model.folders folder=model.folder hasSelectedDocuments=hasSelectedDocuments
|
||||||
onDeleteDocument=(action 'onDeleteDocument') onMoveDocument=(action 'onMoveDocument')}}
|
onDeleteDocument=(action 'onDeleteDocument') onMoveDocument=(action 'onMoveDocument')}}
|
||||||
{{folder/documents-list documents=model.documents folders=model.folders folder=model.folder isFolderOwner=model.isFolderOwner isEditor=model.isEditor
|
{{folder/documents-list documents=model.documents folders=model.folders folder=model.folder templates=model.templates isFolderOwner=model.isFolderOwner isEditor=model.isEditor
|
||||||
onDocumentsChecked=(action 'onDocumentsChecked') onDeleteSpace=(action 'onDeleteSpace') onImport=(action 'onImport')}}
|
onDocumentsChecked=(action 'onDocumentsChecked') onDeleteSpace=(action 'onDeleteSpace') onImport=(action 'onImport')}}
|
||||||
{{/layout/zone-content}}
|
{{/layout/zone-content}}
|
||||||
{{/layout/zone-container}}
|
{{/layout/zone-container}}
|
|
@ -32,8 +32,8 @@ export default Ember.Service.extend({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
getSavedTemplates() {
|
getSavedTemplates(folderId) {
|
||||||
return this.get('ajax').request(`templates`, {
|
return this.get('ajax').request(`templates/${folderId}`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (is.not.array(response)) {
|
if (is.not.array(response)) {
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{folder/start-document folder=folder isEditor=isEditor onImport=(action 'onImport') onHideDocumentWizard=(action 'onHideDocumentWizard')}}
|
{{folder/start-document folder=folder templates=templates isEditor=isEditor onImport=(action 'onImport') onHideDocumentWizard=(action 'onHideDocumentWizard')}}
|
||||||
|
|
||||||
{{#if emptyState}}
|
{{#if emptyState}}
|
||||||
{{#if canCreate}}
|
{{#if canCreate}}
|
||||||
|
|
|
@ -135,8 +135,8 @@ func RegisterEndpoints(rt *env.Runtime, s *domain.Store) {
|
||||||
Add(rt, RoutePrefixPrivate, "search", []string{"POST", "OPTIONS"}, nil, document.SearchDocuments)
|
Add(rt, RoutePrefixPrivate, "search", []string{"POST", "OPTIONS"}, nil, document.SearchDocuments)
|
||||||
|
|
||||||
Add(rt, RoutePrefixPrivate, "templates", []string{"POST", "OPTIONS"}, nil, template.SaveAs)
|
Add(rt, RoutePrefixPrivate, "templates", []string{"POST", "OPTIONS"}, nil, template.SaveAs)
|
||||||
Add(rt, RoutePrefixPrivate, "templates", []string{"GET", "OPTIONS"}, nil, template.SavedList)
|
|
||||||
Add(rt, RoutePrefixPrivate, "templates/{templateID}/folder/{folderID}", []string{"POST", "OPTIONS"}, []string{"type", "saved"}, template.Use)
|
Add(rt, RoutePrefixPrivate, "templates/{templateID}/folder/{folderID}", []string{"POST", "OPTIONS"}, []string{"type", "saved"}, template.Use)
|
||||||
|
Add(rt, RoutePrefixPrivate, "templates/{folderID}", []string{"GET", "OPTIONS"}, nil, template.SavedList)
|
||||||
|
|
||||||
Add(rt, RoutePrefixPrivate, "sections", []string{"GET", "OPTIONS"}, nil, section.GetSections)
|
Add(rt, RoutePrefixPrivate, "sections", []string{"GET", "OPTIONS"}, nil, section.GetSections)
|
||||||
Add(rt, RoutePrefixPrivate, "sections", []string{"POST", "OPTIONS"}, nil, section.RunSectionCommand)
|
Add(rt, RoutePrefixPrivate, "sections", []string{"POST", "OPTIONS"}, nil, section.RunSectionCommand)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue