Skip to content

Commit

Permalink
Merge pull request #61 from documize/doc-wiki-layout
Browse files Browse the repository at this point in the history
switch between docs and wiki layout
  • Loading branch information
HarveyKandola authored Nov 21, 2016
2 parents 0819e04 + 7e14651 commit e0d2dd4
Show file tree
Hide file tree
Showing 18 changed files with 704 additions and 620 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The mission is to bring software dev inspired features (refactoring, testing, li

## Latest version

v0.32.0
v0.33.0

## OS Support

Expand Down
15 changes: 15 additions & 0 deletions app/app/components/document/document-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
didReceiveAttrs() {
this.set('saveTemplate.name', this.get('document.name'));
this.set('saveTemplate.description', this.get('document.excerpt'));

let doc = this.get('document');

this.set('layoutLabel', doc.get('layout') === 'doc' ? 'Wiki style' : 'Document style');
},

didRender() {
Expand All @@ -53,6 +57,17 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
window.print();
},

changeLayout() {
let doc = this.get('document');
let layout = doc.get('layout') === 'doc' ? 'wiki' : 'doc';

doc.set('layout', layout);

this.attrs.onSaveMeta(doc);

this.set('layoutLabel', doc.get('layout') === 'doc' ? 'Wiki style' : 'Document style');
},

saveTemplate() {
var name = this.get('saveTemplate.name');
var excerpt = this.get('saveTemplate.description');
Expand Down
1 change: 1 addition & 0 deletions app/app/components/folder/folders-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
title: "Empty",
description: "An empty canvas for your words",
img: "template-blank",
layout: "doc",
locked: true
};

Expand Down
1 change: 1 addition & 0 deletions app/app/models/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default Model.extend({
userId: attr('string'),
tags: attr('string'),
template: attr('boolean'),
layout: attr('string'),

// client-side property
selected: attr('boolean', { defaultValue: false }),
Expand Down
10 changes: 10 additions & 0 deletions app/app/styles/print.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
display: none !important;
}

.zone-content {
padding: 0 !important;
}

.document-view {
.attachment-zone,
.document-summary,
Expand All @@ -28,4 +32,10 @@
display: block !important;
}
}

.doc-layout {
padding: 0 !important;
box-shadow: none !important;
margin: 0 !important;
}
}
10 changes: 10 additions & 0 deletions app/app/styles/view/document/content.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
.wiki-layout {

}

.doc-layout {
padding: 60px 50px;
box-shadow: 0 0 0 0.75pt $color-stroke,0 0 3pt 0.75pt $color-stroke;
margin: 30px 40px 50px 40px;
}

.document-view {
.print-title {
display: none;
Expand Down
6 changes: 6 additions & 0 deletions app/app/templates/components/document/document-toolbar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@

{{#dropdown-menu target="document-toolbar-menu" position="bottom right" open="click" onOpenCallback=(action 'onMenuOpen') onCloseCallback=(action 'onMenuOpen')}}
<ul class="menu">
{{#if isEditor}}
<li class="item" {{action 'changeLayout'}} >{{layoutLabel}}</li>
<li class="divider"></li>
{{/if}}

<li class="item" id="print-document-button" {{action 'printDocument'}}>Print</li>

{{#if isEditor}}
<li class="divider"></li>
<li class="item" id="delete-document-button">Delete</li>
Expand Down
2 changes: 1 addition & 1 deletion app/app/templates/components/document/document-view.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="document-view">
<div class="document-view {{document.layout}}-layout">
{{#if document.template}}
<div class="is-template">TEMPLATE</div>
{{/if}}
Expand Down
13 changes: 9 additions & 4 deletions app/app/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
//
// This software (Documize Community Edition) is licensed under
// 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>.
// by contacting <sales@documize.com>.
//
// https://documize.com

Expand All @@ -14,5 +14,10 @@ export default {
Public: 1,
Private: 2,
Protected: 3
}
};
},

DisplayLayout: {
DisplayLayoutDoc: "doc",
DisplayLayoutWiki: "wiki"
}
};
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "documize",
"version": "0.32.0",
"version": "0.33.0",
"description": "The Document IDE",
"private": true,
"directories": {
Expand Down
21 changes: 12 additions & 9 deletions core/api/endpoint/templates_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,12 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
d.Excerpt = "A new document"
d.Slug = utility.MakeSlug(d.Title)
d.Tags = ""
d.Layout = "doc"
d.LabelID = folderID
documentID := util.UniqueID()
d.RefID = documentID

var pages = []entity.Page{}
//var pages = make([]entity.Page, 1, 1)
//pages[0] = entity.Page{}
//pages[0].Title = "Heading"
//pages[0].Body = "<p>Some content here.</p>"
//pages[0].Level = 1
//pages[0].Sequence = 1

var attachments = []entity.Attachment{}

// Fetch document and associated pages, attachments if we have template ID
Expand Down Expand Up @@ -394,13 +388,22 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
}

for _, page := range pages {
meta, err2 := p.GetPageMeta(page.RefID)
if err2 != nil {
log.IfErr(tx.Rollback())
writeGeneralSQLError(w, method, err)
return
}

page.DocumentID = documentID
pageID := util.UniqueID()
page.RefID = pageID

meta := entity.PageMeta{}
// meta := entity.PageMeta{}
meta.PageID = pageID
meta.RawBody = page.Body
meta.DocumentID = documentID

// meta.RawBody = page.Body

model := models.PageModel{}
model.Page = page
Expand Down
3 changes: 3 additions & 0 deletions core/api/entity/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type Document struct {
Slug string `json:"-"`
Tags string `json:"tags"`
Template bool `json:"template"`
Layout string `json:"layout"`
}

// SetDefaults ensures on blanks and cleans.
Expand All @@ -161,6 +162,8 @@ func (d *Document) SetDefaults() {
if len(d.Title) == 0 {
d.Title = "Document"
}

d.Layout = "doc"
}

// Attachment represents an attachment to a document.
Expand Down
19 changes: 11 additions & 8 deletions core/api/request/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ func (p *Persister) AddDocument(document entity.Document) (err error) {
document.OrgID = p.Context.OrgID
document.Created = time.Now().UTC()
document.Revised = document.Created // put same time in both fields
if document.Layout == "" {
document.Layout = "doc"
}

stmt, err := p.Context.Transaction.Preparex("INSERT INTO document (refId, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
stmt, err := p.Context.Transaction.Preparex("INSERT INTO document (refId, orgid, labelid, userid, job, location, title, excerpt, slug, tags, template, layout, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
defer utility.Close(stmt)

if err != nil {
log.Error("Unable to prepare insert for document", err)
return
}

_, err = stmt.Exec(document.RefID, document.OrgID, document.LabelID, document.UserID, document.Job, document.Location, document.Title, document.Excerpt, document.Slug, document.Tags, document.Template, document.Created, document.Revised)
_, err = stmt.Exec(document.RefID, document.OrgID, document.LabelID, document.UserID, document.Job, document.Location, document.Title, document.Excerpt, document.Slug, document.Tags, document.Template, document.Layout, document.Created, document.Revised)

if err != nil {
log.Error("Unable to execute insert for document", err)
Expand All @@ -53,7 +56,7 @@ func (p *Persister) AddDocument(document entity.Document) (err error) {
func (p *Persister) GetDocument(id string) (document entity.Document, err error) {
err = nil

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)

if err != nil {
Expand Down Expand Up @@ -112,7 +115,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.
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 {
log.Error(fmt.Sprintf("Unable to execute select documents for org %s", p.Context.OrgID), err)
Expand All @@ -125,7 +128,7 @@ func (p *Persister) GetDocuments() (documents []entity.Document, err error) {
// 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) {
err = nil
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 {
log.Error(fmt.Sprintf("Unable to execute select documents for org %s", p.Context.OrgID), err)
Expand All @@ -141,7 +144,7 @@ func (p *Persister) GetDocumentsByTag(tag string) (documents []entity.Document,
tagQuery := "tags LIKE '%#" + tag + "#%'"

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=?
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)))
Expand All @@ -166,7 +169,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.
func (p *Persister) GetDocumentTemplates() (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=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=?
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)))
Expand Down Expand Up @@ -283,7 +286,7 @@ func (p *Persister) SearchDocument(keywords string) (results []entity.DocumentSe
func (p *Persister) UpdateDocument(document entity.Document) (err error) {
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)

if err != nil {
Expand Down
1 change: 1 addition & 0 deletions core/api/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func ConvertFileResult(filename string, fileResult *api.DocumentConversionRespon
document.LabelID = ""
document.Job = ""
document.Location = filename

if fileResult != nil {
if len(fileResult.Pages) > 0 {
document.Title = fileResult.Pages[0].Title
Expand Down
1 change: 1 addition & 0 deletions core/database/scripts/autobuild/db_00000.sql
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ CREATE TABLE IF NOT EXISTS `document` (
`slug` NVARCHAR(2000) NOT NULL,
`tags` NVARCHAR(1000) NOT NULL DEFAULT '',
`template` BOOL NOT NULL DEFAULT 0,
`layout` CHAR(10) NOT NULL DEFAULT 'doc',
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT pk_refid PRIMARY KEY (refid),
Expand Down
2 changes: 2 additions & 0 deletions core/database/scripts/autobuild/db_00007.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* community edition */
ALTER TABLE document ADD COLUMN `layout` CHAR(10) NOT NULL DEFAULT 'doc' AFTER `template`;
2 changes: 1 addition & 1 deletion core/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ProdInfo struct {
// Product returns product edition details
func Product() (p ProdInfo) {
p.Major = "0"
p.Minor = "32"
p.Minor = "33"
p.Patch = "0"
p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch)
p.Edition = "Community"
Expand Down
Loading

0 comments on commit e0d2dd4

Please sign in to comment.