mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
Display category names in documents list (space view)
We pre-fetch category names and attach them to documents.
This commit is contained in:
parent
1d4a20cdfe
commit
5467771542
8 changed files with 804 additions and 722 deletions
|
@ -166,9 +166,6 @@ func (h *Handler) BySpace(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by title.
|
|
||||||
sort.Sort(doc.ByName(documents))
|
|
||||||
|
|
||||||
// Remove documents that cannot be seen due to lack of
|
// Remove documents that cannot be seen due to lack of
|
||||||
// category view/access permission.
|
// category view/access permission.
|
||||||
cats, err := h.Store.Category.GetBySpace(ctx, spaceID)
|
cats, err := h.Store.Category.GetBySpace(ctx, spaceID)
|
||||||
|
@ -178,6 +175,30 @@ func (h *Handler) BySpace(w http.ResponseWriter, r *http.Request) {
|
||||||
// Keep the latest version when faced with multiple versions.
|
// Keep the latest version when faced with multiple versions.
|
||||||
filtered = FilterLastVersion(filtered)
|
filtered = FilterLastVersion(filtered)
|
||||||
|
|
||||||
|
// Sort document list by ID.
|
||||||
|
sort.Sort(doc.ByID(filtered))
|
||||||
|
|
||||||
|
// Attach category membership to each document.
|
||||||
|
// Put category names into map for easier retrieval.
|
||||||
|
catNames := make(map[string]string)
|
||||||
|
for i := range cats {
|
||||||
|
catNames[cats[i].RefID] = cats[i].Name
|
||||||
|
}
|
||||||
|
// Loop the smaller list which is categories assigned to documents.
|
||||||
|
for i := range members {
|
||||||
|
// Get name of category
|
||||||
|
cn := catNames[members[i].CategoryID]
|
||||||
|
// Find document that is assigned this category.
|
||||||
|
j := sort.Search(len(filtered), func(k int) bool { return filtered[k].RefID <= members[i].DocumentID })
|
||||||
|
// Attach category name to document
|
||||||
|
if j < len(filtered) && filtered[j].RefID == members[i].DocumentID {
|
||||||
|
filtered[j].Category = append(filtered[j].Category, cn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort document list by title.
|
||||||
|
sort.Sort(doc.ByName(filtered))
|
||||||
|
|
||||||
response.WriteJSON(w, filtered)
|
response.WriteJSON(w, filtered)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1422
embed/bindata.go
1422
embed/bindata.go
File diff suppressed because one or more lines are too long
16
gui/app/components/folder/document-categories.js
Normal file
16
gui/app/components/folder/document-categories.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// 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
|
||||||
|
|
||||||
|
import Component from '@ember/component';
|
||||||
|
|
||||||
|
export default Component.extend({
|
||||||
|
classNames: ['categories'],
|
||||||
|
});
|
|
@ -31,14 +31,18 @@ export default Model.extend({
|
||||||
versionId: attr('string'),
|
versionId: attr('string'),
|
||||||
versionOrder: attr('number', { defaultValue: 0 }),
|
versionOrder: attr('number', { defaultValue: 0 }),
|
||||||
groupId: attr('string'),
|
groupId: attr('string'),
|
||||||
|
created: attr(),
|
||||||
|
revised: attr(),
|
||||||
|
|
||||||
|
// read-only presentation field
|
||||||
|
category: attr({defaultValue() {return [];}}),
|
||||||
|
|
||||||
// client-side property
|
|
||||||
selected: attr('boolean', { defaultValue: false }),
|
|
||||||
slug: computed('name', function () {
|
slug: computed('name', function () {
|
||||||
return stringUtil.makeSlug(this.get('name'));
|
return stringUtil.makeSlug(this.get('name'));
|
||||||
}),
|
}),
|
||||||
created: attr(),
|
|
||||||
revised: attr(),
|
// client-side property
|
||||||
|
selected: attr('boolean', { defaultValue: false }),
|
||||||
|
|
||||||
isDraft: computed('lifecycle', function () {
|
isDraft: computed('lifecycle', function () {
|
||||||
let constants = this.get('constants');
|
let constants = this.get('constants');
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
@include border-radius(5px);
|
@include border-radius(5px);
|
||||||
background-color: map-get($gray-shades, 300);
|
background-color: map-get($gray-shades, 300);
|
||||||
padding: 0.25rem 1rem;
|
padding: 0.25rem 1rem;
|
||||||
|
margin-right: 20px;
|
||||||
|
|
||||||
> .draft {
|
> .draft {
|
||||||
color: map-get($yellow-shades, 600);
|
color: map-get($yellow-shades, 600);
|
||||||
|
@ -90,12 +91,34 @@
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.categories {
|
||||||
|
display: inline-block;
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
> .category {
|
||||||
|
padding: 0 15px 0 0;
|
||||||
|
display: inline-block;
|
||||||
|
|
||||||
|
> .dicon {
|
||||||
|
color: map-get($gray-shades, 500);
|
||||||
|
font-size: 20px;
|
||||||
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .name {
|
||||||
|
display: inline-block;
|
||||||
|
color: map-get($gray-shades, 800);
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.hashtags {
|
.hashtags {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 10px 0 10px;
|
padding: 0;
|
||||||
|
|
||||||
> .hashtag {
|
> .hashtag {
|
||||||
padding: 0 10px 0 10px;
|
padding: 0 15px 0 0;
|
||||||
|
|
||||||
> .dicon {
|
> .dicon {
|
||||||
color: map-get($gray-shades, 500);
|
color: map-get($gray-shades, 500);
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
{{#if categories}}
|
||||||
|
{{#each categories as |cat|}}
|
||||||
|
<div class="category">
|
||||||
|
<i class="dicon {{constants.Icon.Category}}" />
|
||||||
|
<div class="name">{{cat}}</div>
|
||||||
|
</div>
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
|
@ -14,7 +14,7 @@
|
||||||
{{document.lifecycleLabel}}
|
{{document.lifecycleLabel}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{folder/document-categories categories=document.category}}
|
||||||
{{folder/document-tags documentTags=document.tags}}
|
{{folder/document-tags documentTags=document.tags}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,9 @@ type Document struct {
|
||||||
VersionID string `json:"versionId"`
|
VersionID string `json:"versionId"`
|
||||||
VersionOrder int `json:"versionOrder"`
|
VersionOrder int `json:"versionOrder"`
|
||||||
GroupID string `json:"groupId"`
|
GroupID string `json:"groupId"`
|
||||||
|
|
||||||
|
// Read-only presentation only data
|
||||||
|
Category []string `json:"category"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults ensures on blanks and cleans.
|
// SetDefaults ensures on blanks and cleans.
|
||||||
|
@ -50,13 +53,20 @@ func (d *Document) SetDefaults() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByName sorts a collection of documents by document Name.
|
// ByName sorts a collection of documents by document name.
|
||||||
type ByName []Document
|
type ByName []Document
|
||||||
|
|
||||||
func (a ByName) Len() int { return len(a) }
|
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) 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) }
|
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.
|
// DocumentMeta details who viewed the document.
|
||||||
type DocumentMeta struct {
|
type DocumentMeta struct {
|
||||||
Viewers []DocumentMetaViewer `json:"viewers"`
|
Viewers []DocumentMetaViewer `json:"viewers"`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue