1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 21:29:42 +02:00
This commit is contained in:
HarveyKandola 2018-07-28 11:43:45 -04:00
parent 743eae5aad
commit d0970c153b
8 changed files with 287 additions and 8 deletions

View file

@ -726,3 +726,36 @@ func (h *Handler) Vote(w http.ResponseWriter, r *http.Request) {
response.WriteEmpty(w) 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

File diff suppressed because one or more lines are too long

View file

@ -22,6 +22,8 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
spaceService: service('folder'), spaceService: service('folder'),
localStorage: service(), localStorage: service(),
templateService: service('template'), templateService: service('template'),
browserSvc: service('browser'),
documentSvc: service('document'),
session: service(), session: service(),
appMeta: service(), appMeta: service(),
pinned: service(), pinned: service(),
@ -29,21 +31,24 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
copyTemplate: true, copyTemplate: true,
copyPermission: true, copyPermission: true,
copyDocument: false, copyDocument: false,
spaceSettings: computed('permissions', function() { spaceSettings: computed('permissions', function() {
return this.get('permissions.spaceOwner') || this.get('permissions.spaceManage'); return this.get('permissions.spaceOwner') || this.get('permissions.spaceManage');
}), }),
deleteSpaceName: '', deleteSpaceName: '',
hasTemplates: computed('templates', function() { hasTemplates: computed('templates', function() {
return this.get('templates.length') > 0; 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: '', emptyDocName: '',
emptyDocNameError: false, emptyDocNameError: false,
templateDocName: '', templateDocName: '',
templateDocNameError: false, templateDocNameError: false,
selectedTemplate: '', selectedTemplate: '',
dropzone: null, dropzone: null,
init() { init() {
@ -71,6 +76,11 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
this.set('pinState.newName', folder.get('name')); this.set('pinState.newName', folder.get('name'));
this.renderTooltips(); this.renderTooltips();
}); });
let cats = this.get('categories');
cats.forEach((cat) => {
cat.set('exportSelected', false);
})
}, },
didInsertElement() { didInsertElement() {
@ -290,6 +300,36 @@ export default Component.extend(ModalMixin, TooltipMixin, AuthMixin, {
let cb = this.get('onRefresh'); let cb = this.get('onRefresh');
cb(); 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");
} }
} }
}); });

View file

@ -13,6 +13,9 @@
space=model.folder space=model.folder
permissions=model.permissions permissions=model.permissions
templates=model.templates templates=model.templates
category=category
categories=model.categories
documents=filteredDocs
onRefresh=(action 'onRefresh') onRefresh=(action 'onRefresh')
onDeleteSpace=(action 'onDeleteSpace')}} onDeleteSpace=(action 'onDeleteSpace')}}

View file

@ -52,5 +52,20 @@ export default Service.extend({
scrollTop: elem.top scrollTop: elem.top
}, 250); }, 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});
} }
}); });

View file

@ -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 // Fetch bulk data
//************************************************** //**************************************************

View file

@ -101,6 +101,13 @@
<div class="button-icon-gap" /> <div class="button-icon-gap" />
{{/if}} {{/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}} {{#if permissions.spaceOwner}}
<div id="space-delete-button" class="button-icon-danger align-middle" data-toggle="tooltip" data-placement="top" title="Delete space"> <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> <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>
</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>

View file

@ -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}/permission", []string{"GET", "OPTIONS"}, nil, permission.GetCategoryPermissions)
AddPrivate(rt, "category/{categoryID}/user", []string{"GET", "OPTIONS"}, nil, permission.GetCategoryViewers) 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 // 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/category/space/{spaceID}", []string{"GET", "OPTIONS"}, nil, category.FetchSpaceData)
AddPrivate(rt, "fetch/document/{documentID}", []string{"GET", "OPTIONS"}, nil, document.FetchDocumentData) AddPrivate(rt, "fetch/document/{documentID}", []string{"GET", "OPTIONS"}, nil, document.FetchDocumentData)