mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
WIP
This commit is contained in:
parent
743eae5aad
commit
d0970c153b
8 changed files with 287 additions and 8 deletions
|
@ -726,3 +726,36 @@ func (h *Handler) Vote(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteEmpty(w)
|
||||
}
|
||||
|
||||
// Export returns content as self-enclosed HTML file.
|
||||
func (h *Handler) Export(w http.ResponseWriter, r *http.Request) {
|
||||
method := "document.Export"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
defer streamutil.Close(r.Body)
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
spec := exportSpec{}
|
||||
err = json.Unmarshal(body, &spec)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
export, err := BuildExport(ctx, *h.Store, spec)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
w.Write([]byte(export))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
|
145
domain/document/export.go
Normal file
145
domain/document/export.go
Normal file
File diff suppressed because one or more lines are too long
|
@ -22,6 +22,8 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
|
|||
spaceService: service('folder'),
|
||||
localStorage: service(),
|
||||
templateService: service('template'),
|
||||
browserSvc: service('browser'),
|
||||
documentSvc: service('document'),
|
||||
session: service(),
|
||||
appMeta: service(),
|
||||
pinned: service(),
|
||||
|
@ -29,21 +31,24 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
|
|||
copyTemplate: true,
|
||||
copyPermission: true,
|
||||
copyDocument: false,
|
||||
|
||||
spaceSettings: computed('permissions', function() {
|
||||
return this.get('permissions.spaceOwner') || this.get('permissions.spaceManage');
|
||||
}),
|
||||
deleteSpaceName: '',
|
||||
|
||||
hasTemplates: computed('templates', function() {
|
||||
return this.get('templates.length') > 0;
|
||||
}),
|
||||
hasCategories: computed('categories', function() {
|
||||
return this.get('categories.length') > 0;
|
||||
}),
|
||||
hasDocuments: computed('documents', function() {
|
||||
return this.get('documents.length') > 0;
|
||||
}),
|
||||
emptyDocName: '',
|
||||
emptyDocNameError: false,
|
||||
templateDocName: '',
|
||||
templateDocNameError: false,
|
||||
selectedTemplate: '',
|
||||
|
||||
dropzone: null,
|
||||
|
||||
init() {
|
||||
|
@ -71,6 +76,11 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
|
|||
this.set('pinState.newName', folder.get('name'));
|
||||
this.renderTooltips();
|
||||
});
|
||||
|
||||
let cats = this.get('categories');
|
||||
cats.forEach((cat) => {
|
||||
cat.set('exportSelected', false);
|
||||
})
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
|
@ -290,6 +300,36 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
|
|||
let cb = this.get('onRefresh');
|
||||
cb();
|
||||
}
|
||||
},
|
||||
|
||||
onShowExport() {
|
||||
this.modalOpen("#space-export-modal", {"show": true});
|
||||
},
|
||||
|
||||
onExport() {
|
||||
let spec = {
|
||||
spaceId: this.get('space.id'),
|
||||
data: [],
|
||||
filterType: '',
|
||||
}
|
||||
|
||||
let cats = this.get('categories');
|
||||
cats.forEach((cat) => {
|
||||
if (cat.get('exportSelected')) spec.data.push(cat.get('id'));
|
||||
});
|
||||
|
||||
if (spec.data.length > 0) {
|
||||
spec.filterType = 'category';
|
||||
} else {
|
||||
spec.filterType = 'space';
|
||||
spec.data.push(this.get('space.id'));
|
||||
}
|
||||
|
||||
this.get('documentSvc').export(spec).then((htmlExport) => {
|
||||
this.get('browserSvc').downloadFile(htmlExport, this.get('space.slug') + '.html');
|
||||
});
|
||||
|
||||
this.modalClose("#space-export-modal");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
space=model.folder
|
||||
permissions=model.permissions
|
||||
templates=model.templates
|
||||
category=category
|
||||
categories=model.categories
|
||||
documents=filteredDocs
|
||||
onRefresh=(action 'onRefresh')
|
||||
onDeleteSpace=(action 'onDeleteSpace')}}
|
||||
|
||||
|
|
|
@ -52,5 +52,20 @@ export default Service.extend({
|
|||
scrollTop: elem.top
|
||||
}, 250);
|
||||
});
|
||||
},
|
||||
|
||||
downloadFile(content, filename) {
|
||||
let b = new Blob([content], {
|
||||
type: 'text/html'
|
||||
});
|
||||
|
||||
const data = window.URL.createObjectURL(b);
|
||||
var link = document.createElement('a');
|
||||
link.href = data;
|
||||
link.download = filename;
|
||||
link.click();
|
||||
|
||||
// For Firefox it is necessary to delay revoking the ObjectURL
|
||||
setTimeout(function() { window.URL.revokeObjectURL(data), 100});
|
||||
}
|
||||
});
|
|
@ -355,6 +355,18 @@ export default Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Export
|
||||
//**************************************************
|
||||
|
||||
export(spec) {
|
||||
return this.get('ajax').post('export', {
|
||||
data: JSON.stringify(spec),
|
||||
contentType: 'json',
|
||||
dataType: 'text/html'
|
||||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Fetch bulk data
|
||||
//**************************************************
|
||||
|
|
|
@ -101,6 +101,13 @@
|
|||
<div class="button-icon-gap" />
|
||||
{{/if}}
|
||||
|
||||
{{#if hasDocuments}}
|
||||
<div id="space-export-button" class="button-icon-danger align-middle" data-toggle="tooltip" data-placement="top" title="Export as HTML" {{action 'onShowExport'}}>
|
||||
<i class="material-icons">import_export</i>
|
||||
</div>
|
||||
<div class="button-icon-gap" />
|
||||
{{/if}}
|
||||
|
||||
{{#if permissions.spaceOwner}}
|
||||
<div id="space-delete-button" class="button-icon-danger align-middle" data-toggle="tooltip" data-placement="top" title="Delete space">
|
||||
<i class="material-icons" data-toggle="modal" data-target="#space-delete-modal" data-backdrop="static">delete</i>
|
||||
|
@ -142,3 +149,25 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="space-export-modal" class="modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">Export as HTML</div>
|
||||
<div class="modal-body">
|
||||
{{#if hasCategories}}
|
||||
<p>Export all space content as HTML or select categories.</p>
|
||||
{{#each categories as |cat|}}
|
||||
{{#ui/ui-checkbox selected=cat.exportSelected}}{{cat.category}}{{/ui/ui-checkbox}}
|
||||
{{/each}}
|
||||
{{else}}
|
||||
<p>All space content will be exported as a single self-enclosed HTML file.</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
|
||||
<button type="button" class="btn btn-success" onclick={{action 'onExport'}}>Export</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -192,6 +192,8 @@ func RegisterEndpoints(rt *env.Runtime, s *domain.Store) {
|
|||
AddPrivate(rt, "category/{categoryID}/permission", []string{"GET", "OPTIONS"}, nil, permission.GetCategoryPermissions)
|
||||
AddPrivate(rt, "category/{categoryID}/user", []string{"GET", "OPTIONS"}, nil, permission.GetCategoryViewers)
|
||||
|
||||
AddPrivate(rt, "export", []string{"POST", "OPTIONS"}, nil, document.Export)
|
||||
|
||||
// fetch methods exist to speed up UI rendering by returning data in bulk
|
||||
AddPrivate(rt, "fetch/category/space/{spaceID}", []string{"GET", "OPTIONS"}, nil, category.FetchSpaceData)
|
||||
AddPrivate(rt, "fetch/document/{documentID}", []string{"GET", "OPTIONS"}, nil, document.FetchDocumentData)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue