1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

Closes #95 -- flat and section style document viewing

This commit is contained in:
Harvey Kandola 2017-04-27 12:46:34 +01:00
parent ef6b7f429c
commit 4a2147189a
8 changed files with 52 additions and 9 deletions

View file

@ -16,6 +16,7 @@ import NotifierMixin from '../../mixins/notifier';
export default Ember.Component.extend(TooltipMixin, NotifierMixin, { export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
documentService: Ember.inject.service('document'), documentService: Ember.inject.service('document'),
sectionService: Ember.inject.service('section'), sectionService: Ember.inject.service('section'),
sessionService: Ember.inject.service('session'),
appMeta: Ember.inject.service(), appMeta: Ember.inject.service(),
userService: Ember.inject.service('user'), userService: Ember.inject.service('user'),
localStorage: Ember.inject.service(), localStorage: Ember.inject.service(),
@ -138,6 +139,14 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
this.showNotification('Template saved'); this.showNotification('Template saved');
this.attrs.onSaveTemplate(name, excerpt); this.attrs.onSaveTemplate(name, excerpt);
return true;
},
onLayoutChange(layout) {
let doc = this.get('document');
doc.set('layout', layout);
this.get('documentService').save(doc);
return true; return true;
} }
} }

View file

@ -25,6 +25,7 @@ export default Model.extend({
userId: attr('string'), userId: attr('string'),
tags: attr('string'), tags: attr('string'),
template: attr('boolean'), template: attr('boolean'),
layout: attr('string'),
// client-side property // client-side property
selected: attr('boolean', { defaultValue: false }), selected: attr('boolean', { defaultValue: false }),

View file

@ -51,7 +51,7 @@
@include content-container(); @include content-container();
@include ease-in(); @include ease-in();
@extend .transition-all; @extend .transition-all;
overflow-x: scroll; overflow-x: auto;
&:hover { &:hover {
.page-title { .page-title {
@ -329,6 +329,28 @@
} }
} }
.document-view-unified {
margin: 0 0 50px 0;
@include content-container();
@include ease-in();
@extend .transition-all;
.is-a-page, .is-a-tab {
padding: 0 !important;
box-shadow: none !important;
background-color: transparent !important;
@include border-radius(0px);
}
.tab-min, .tab-max {
padding: 0 !important;
}
.start-section {
height: 50px !important;
}
}
.dropdown-page-toolbar { .dropdown-page-toolbar {
width: 300px; width: 300px;
} }

View file

@ -1,4 +1,4 @@
<div class="document-view"> <div class="document-view {{if (is-equal document.layout 'doc') 'document-view-unified'}}">
{{#if hasPages}} {{#if hasPages}}
{{#each pages key="id" as |page index|}} {{#each pages key="id" as |page index|}}

View file

@ -43,6 +43,13 @@
{{#dropdown-menu target="sidebar-zone-more-button" position="bottom left" open="click" onOpenCallback=(action 'onMenuOpen') onCloseCallback=(action 'onMenuOpen')}} {{#dropdown-menu target="sidebar-zone-more-button" position="bottom left" open="click" onOpenCallback=(action 'onMenuOpen') onCloseCallback=(action 'onMenuOpen')}}
<ul class="menu"> <ul class="menu">
{{#if session.authenticated}} {{#if session.authenticated}}
{{#if (is-equal document.layout 'section')}}
<li class="item" {{action 'onLayoutChange' 'doc'}}>Flat view</li>
<li class="divider"></li>
{{else}}
<li class="item" {{action 'onLayoutChange' 'section'}}>Section view</li>
<li class="divider"></li>
{{/if}}
{{#if pinState.isPinned}} {{#if pinState.isPinned}}
<li class="item" {{action 'onUnpin'}}>Unpin</li> <li class="item" {{action 'onUnpin'}}>Unpin</li>
{{else}} {{else}}

View file

@ -166,6 +166,7 @@ type Document struct {
Slug string `json:"-"` Slug string `json:"-"`
Tags string `json:"tags"` Tags string `json:"tags"`
Template bool `json:"template"` Template bool `json:"template"`
Layout string `json:"layout"`
} }
// SetDefaults ensures on blanks and cleans. // SetDefaults ensures on blanks and cleans.

View file

@ -49,7 +49,7 @@ func (p *Persister) AddDocument(document entity.Document) (err error) {
// GetDocument fetches the document record with the given id fromt the document table and audits that it has been got. // GetDocument fetches the document record with the given id fromt the document table and audits that it has been got.
func (p *Persister) GetDocument(id string) (document entity.Document, err error) { func (p *Persister) GetDocument(id string) (document entity.Document, err error) {
stmt, err := Db.Preparex("SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised FROM document WHERE orgid=? and refid=?") stmt, err := Db.Preparex("SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised FROM document WHERE orgid=? and refid=?")
defer utility.Close(stmt) defer utility.Close(stmt)
if err != nil { if err != nil {
@ -108,7 +108,7 @@ func (p *Persister) GetDocumentMeta(id string) (meta entity.DocumentMeta, err er
// GetDocuments returns a slice containg all of the the documents for the client's organisation, with the most recient first. // GetDocuments returns a slice containg all of the the documents for the client's organisation, with the most recient first.
func (p *Persister) GetDocuments() (documents []entity.Document, err error) { func (p *Persister) GetDocuments() (documents []entity.Document, err error) {
err = Db.Select(&documents, "SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised FROM document WHERE orgid=? AND template=0 ORDER BY revised DESC", p.Context.OrgID) err = 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=0 ORDER BY revised DESC", p.Context.OrgID)
if err != nil { if err != nil {
log.Error(fmt.Sprintf("Unable to execute select documents for org %s", p.Context.OrgID), err) log.Error(fmt.Sprintf("Unable to execute select documents for org %s", p.Context.OrgID), err)
@ -120,7 +120,7 @@ func (p *Persister) GetDocuments() (documents []entity.Document, err error) {
// GetDocumentsByFolder returns a slice containing the documents for a given folder, most recient first. // GetDocumentsByFolder returns a slice containing the documents for a given folder, most recient first.
func (p *Persister) GetDocumentsByFolder(folderID string) (documents []entity.Document, err error) { func (p *Persister) GetDocumentsByFolder(folderID string) (documents []entity.Document, err error) {
err = Db.Select(&documents, "SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised FROM document WHERE orgid=? AND template=0 AND labelid=? ORDER BY revised DESC", p.Context.OrgID, folderID) err = 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=0 AND labelid=? ORDER BY revised DESC", p.Context.OrgID, folderID)
if err != nil { if err != nil {
log.Error(fmt.Sprintf("Unable to execute select documents for org %s", p.Context.OrgID), err) log.Error(fmt.Sprintf("Unable to execute select documents for org %s", p.Context.OrgID), err)
@ -136,7 +136,7 @@ func (p *Persister) GetDocumentsByTag(tag string) (documents []entity.Document,
tagQuery := "tags LIKE '%#" + tag + "#%'" tagQuery := "tags LIKE '%#" + tag + "#%'"
err = Db.Select(&documents, err = Db.Select(&documents,
`SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised FROM document WHERE orgid=? AND template=0 AND `+tagQuery+` 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=0 AND `+tagQuery+` 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=?
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=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))) 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)))
@ -161,7 +161,7 @@ func (p *Persister) GetDocumentsByTag(tag string) (documents []entity.Document,
// GetDocumentTemplates returns a slice containing the documents available as templates to the client's organisation, in title order. // GetDocumentTemplates returns a slice containing the documents available as templates to the client's organisation, in title order.
func (p *Persister) GetDocumentTemplates() (documents []entity.Document, err error) { func (p *Persister) GetDocumentTemplates() (documents []entity.Document, err error) {
err = Db.Select(&documents, err = Db.Select(&documents,
`SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, 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=?
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=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))) 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)))
@ -203,7 +203,7 @@ AND d.template=0`, orgID)
// GetDocumentList returns a slice containing the documents available as templates to the client's organisation, in title order. // GetDocumentList returns a slice containing the documents available as templates to the client's organisation, in title order.
func (p *Persister) GetDocumentList() (documents []entity.Document, err error) { func (p *Persister) GetDocumentList() (documents []entity.Document, err error) {
err = Db.Select(&documents, err = Db.Select(&documents,
`SELECT id, refid, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised FROM document WHERE orgid=? AND template=0 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=0 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=?
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=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))) 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)))
@ -301,7 +301,7 @@ func (p *Persister) SearchDocument(keywords string) (results []entity.DocumentSe
func (p *Persister) UpdateDocument(document entity.Document) (err error) { func (p *Persister) UpdateDocument(document entity.Document) (err error) {
document.Revised = time.Now().UTC() document.Revised = time.Now().UTC()
stmt, err := p.Context.Transaction.PrepareNamed("UPDATE document SET labelid=:labelid, userid=:userid, job=:job, location=:location, title=:title, excerpt=:excerpt, slug=:slug, tags=:tags, template=:template, revised=:revised WHERE orgid=:orgid AND refid=:refid") stmt, err := p.Context.Transaction.PrepareNamed("UPDATE document SET labelid=:labelid, userid=:userid, job=:job, location=:location, title=:title, excerpt=:excerpt, slug=:slug, tags=:tags, template=:template, layout=:layout, revised=:revised WHERE orgid=:orgid AND refid=:refid")
defer utility.Close(stmt) defer utility.Close(stmt)
if err != nil { if err != nil {

View file

@ -0,0 +1,3 @@
/* community edition */
ALTER TABLE document ALTER COLUMN `layout` SET DEFAULT 'section';
UPDATE document SET layout='section';