mirror of
https://github.com/documize/community.git
synced 2025-07-18 20:59: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
|
||||
}
|
||||
|
||||
// Sort by title.
|
||||
sort.Sort(doc.ByName(documents))
|
||||
|
||||
// Remove documents that cannot be seen due to lack of
|
||||
// category view/access permission.
|
||||
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.
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
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'),
|
||||
versionOrder: attr('number', { defaultValue: 0 }),
|
||||
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 () {
|
||||
return stringUtil.makeSlug(this.get('name'));
|
||||
}),
|
||||
created: attr(),
|
||||
revised: attr(),
|
||||
|
||||
// client-side property
|
||||
selected: attr('boolean', { defaultValue: false }),
|
||||
|
||||
isDraft: computed('lifecycle', function () {
|
||||
let constants = this.get('constants');
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
@include border-radius(5px);
|
||||
background-color: map-get($gray-shades, 300);
|
||||
padding: 0.25rem 1rem;
|
||||
margin-right: 20px;
|
||||
|
||||
> .draft {
|
||||
color: map-get($yellow-shades, 600);
|
||||
|
@ -90,12 +91,34 @@
|
|||
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 {
|
||||
display: inline-block;
|
||||
padding: 0 10px 0 10px;
|
||||
padding: 0;
|
||||
|
||||
> .hashtag {
|
||||
padding: 0 10px 0 10px;
|
||||
padding: 0 15px 0 0;
|
||||
|
||||
> .dicon {
|
||||
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}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{folder/document-categories categories=document.category}}
|
||||
{{folder/document-tags documentTags=document.tags}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -39,6 +39,9 @@ type Document struct {
|
|||
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.
|
||||
|
@ -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
|
||||
|
||||
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"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue