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
|
||||
}
|
||||
|
||||
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 {
|
||||
ctx.Transaction.Rollback()
|
||||
err = errors.Wrap(err, "cannot updater new document")
|
||||
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.
|
||||
// if err != nil {
|
||||
// ctx.Transaction.Rollback()
|
||||
// err = errors.Wrap(err, "cannot updater new document")
|
||||
// return
|
||||
// }
|
||||
|
||||
store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
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.
|
||||
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,
|
||||
`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=?
|
||||
|
@ -174,7 +174,33 @@ func (s Scope) Templates(ctx domain.RequestContext) ( documents []doc.Document,
|
|||
ctx.UserID)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -133,6 +133,7 @@ type DocumentStorer interface {
|
|||
GetByTag(ctx RequestContext, tag string) (documents []doc.Document, err error)
|
||||
DocumentList(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)
|
||||
PublicDocuments(ctx RequestContext, orgID string) (documents []doc.SitemapDocument, 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"
|
||||
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 {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
|
@ -67,8 +73,10 @@ func (h *Handler) SavedList(w http.ResponseWriter, r *http.Request) {
|
|||
t.Dated = d.Created
|
||||
t.Type = template.TypePrivate
|
||||
|
||||
if d.LabelID == folderID {
|
||||
templates = append(templates, t)
|
||||
}
|
||||
}
|
||||
|
||||
response.WriteJSON(w, templates)
|
||||
}
|
||||
|
|
|
@ -12,14 +12,13 @@
|
|||
import Ember from 'ember';
|
||||
import NotifierMixin from '../../mixins/notifier';
|
||||
|
||||
|
||||
const {
|
||||
computed,
|
||||
} = Ember;
|
||||
|
||||
export default Ember.Component.extend(NotifierMixin, {
|
||||
localStorage: Ember.inject.service(),
|
||||
appMeta: Ember.inject.service(),
|
||||
templateService: Ember.inject.service('template'),
|
||||
canEditTemplate: "",
|
||||
importedDocuments: [],
|
||||
savedTemplates: [],
|
||||
|
@ -27,10 +26,24 @@ export default Ember.Component.extend(NotifierMixin, {
|
|||
newDocumentName: 'New Document',
|
||||
newDocumentNameMissing: computed.empty('newDocumentName'),
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
didInsertElement() {
|
||||
this.setupImport();
|
||||
},
|
||||
|
||||
didReceiveAttrs() {
|
||||
this.setupTemplates();
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
if (is.not.null(this.get('drop'))) {
|
||||
this.get('drop').destroy();
|
||||
this.set('drop', null);
|
||||
}
|
||||
},
|
||||
|
||||
setupTemplates() {
|
||||
let templates = this.get('templates');
|
||||
|
||||
this.get('templateService').getSavedTemplates().then((saved) => {
|
||||
let emptyTemplate = {
|
||||
id: "0",
|
||||
title: "Empty",
|
||||
|
@ -39,20 +52,8 @@ export default Ember.Component.extend(NotifierMixin, {
|
|||
locked: true
|
||||
};
|
||||
|
||||
saved.unshiftObject(emptyTemplate);
|
||||
this.set('savedTemplates', saved);
|
||||
});
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
this.setupImport();
|
||||
},
|
||||
|
||||
willDestroyElement() {
|
||||
if (is.not.null(this.get('drop'))) {
|
||||
this.get('drop').destroy();
|
||||
this.set('drop', null);
|
||||
}
|
||||
templates.unshiftObject(emptyTemplate);
|
||||
this.set('savedTemplates', templates);
|
||||
},
|
||||
|
||||
setupImport() {
|
||||
|
@ -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, {
|
||||
documentService: Ember.inject.service('document'),
|
||||
folderService: Ember.inject.service('folder'),
|
||||
templateService: Ember.inject.service('template'),
|
||||
session: Ember.inject.service(''),
|
||||
folder: {},
|
||||
|
||||
|
@ -41,7 +42,8 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, {
|
|||
isEditor: this.get('isEditor'),
|
||||
isFolderOwner: this.get('isFolderOwner'),
|
||||
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-toolbar folders=model.folders folder=model.folder hasSelectedDocuments=hasSelectedDocuments
|
||||
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')}}
|
||||
{{/layout/zone-content}}
|
||||
{{/layout/zone-container}}
|
|
@ -32,8 +32,8 @@ export default Ember.Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
getSavedTemplates() {
|
||||
return this.get('ajax').request(`templates`, {
|
||||
getSavedTemplates(folderId) {
|
||||
return this.get('ajax').request(`templates/${folderId}`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) {
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
{{/each}}
|
||||
</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 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, "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/{folderID}", []string{"GET", "OPTIONS"}, nil, template.SavedList)
|
||||
|
||||
Add(rt, RoutePrefixPrivate, "sections", []string{"GET", "OPTIONS"}, nil, section.GetSections)
|
||||
Add(rt, RoutePrefixPrivate, "sections", []string{"POST", "OPTIONS"}, nil, section.RunSectionCommand)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue