/
doc.go
120 lines (102 loc) · 3.71 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// 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
package doc
import (
"strings"
"time"
"github.com/documize/community/model"
"github.com/documize/community/model/workflow"
)
// Document represents the purpose of Documize.
type Document struct {
model.BaseEntity
OrgID string `json:"orgId"`
SpaceID string `json:"spaceId"`
UserID string `json:"userId"`
Job string `json:"job"`
Location string `json:"location"`
Name string `json:"name"`
Excerpt string `json:"excerpt"`
Slug string `json:"-"`
Tags string `json:"tags"`
Template bool `json:"template"`
Protection workflow.Protection `json:"protection"`
Approval workflow.Approval `json:"approval"`
Lifecycle workflow.Lifecycle `json:"lifecycle"`
Versioned bool `json:"versioned"`
VersionID string `json:"versionId"`
VersionOrder int `json:"versionOrder"`
GroupID string `json:"groupId"`
// Read-only presentation only data
Category []string `json:"category"`
}
// SetDefaults ensures on blanks and cleans.
func (d *Document) SetDefaults() {
d.Name = strings.TrimSpace(d.Name)
if len(d.Name) == 0 {
d.Name = "Document"
}
}
// ByName sorts a collection of documents by document name.
type ByName []Document
func (a ByName) Len() int { return len(a) }
func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByName) Less(i, j int) bool { return strings.ToLower(a[i].Name) < strings.ToLower(a[j].Name) }
// ByID sorts a collection of documents by document ID.
type ByID []Document
func (a ByID) Len() int { return len(a) }
func (a ByID) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByID) Less(i, j int) bool { return a[i].RefID > a[j].RefID }
// DocumentMeta details who viewed the document.
type DocumentMeta struct {
Viewers []DocumentMetaViewer `json:"viewers"`
Editors []DocumentMetaEditor `json:"editors"`
}
// DocumentMetaViewer contains the "view" metatdata content.
type DocumentMetaViewer struct {
UserID string `json:"userId"`
Created time.Time `json:"created"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
// DocumentMetaEditor contains the "edit" metatdata content.
type DocumentMetaEditor struct {
SectionID string `json:"pageId"`
UserID string `json:"userId"`
Action string `json:"action"`
Created time.Time `json:"created"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
}
// UploadModel details the job ID of an uploaded document.
type UploadModel struct {
JobID string `json:"jobId"`
}
// SitemapDocument details a document that can be exposed via Sitemap.
type SitemapDocument struct {
DocumentID string
Document string
SpaceID string
Space string
Revised time.Time
}
// Version points to a version of a document.
type Version struct {
VersionID string `json:"versionId"`
DocumentID string `json:"documentId"`
Lifecycle workflow.Lifecycle `json:"lifecycle"`
}
// DuplicateModel is used to create a copy of a document.
type DuplicateModel struct {
SpaceID string `json:"spaceId"`
DocumentID string `json:"documentId"`
Name string `json:"documentName"`
}