1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-21 06:09:42 +02:00

implemented delete reusable content block

This commit is contained in:
Harvey Kandola 2017-01-21 18:14:31 -08:00
parent 2493a09ba9
commit fc9127e165
12 changed files with 130 additions and 16 deletions

View file

@ -106,6 +106,11 @@ export default Ember.Component.extend(TooltipMixin, NotifierMixin, {
this.attrs.onInsertBlock(block);
},
onDeleteBlock(id) {
this.set('blocks', this.get('blocks').filter((item) => item.get('id') !== id));
this.attrs.onDeleteBlock(id);
},
scrollTop() {
this.set('showScrollTool', false);

View file

@ -12,12 +12,22 @@
import Ember from 'ember';
import NotifierMixin from '../../mixins/notifier';
const {
computed,
} = Ember;
export default Ember.Component.extend(NotifierMixin, {
display: 'section', // which CSS to use
hasTemplates: false,
didReceiveAttrs() {
this.set('hasBlocks', this.get('blocks.length') > 0);
let blocks = this.get('blocks');
this.set('hasBlocks', blocks.get('length') > 0);
blocks.forEach((b) => {
b.set('deleteId', `delete-block-button-${b.id}`);
});
},
didRender() {
@ -42,6 +52,10 @@ export default Ember.Component.extend(NotifierMixin, {
this.attrs.onAddSection(section);
},
onDeleteBlock(id) {
this.attrs.onDeleteBlock(id);
},
onInsertBlock(block) {
this.attrs.onInsertBlock(block);
}

View file

@ -21,10 +21,6 @@ export default Ember.Component.extend({
return is.not.undefined(this.get('page.excerpt'));
}),
didReceiveAttrs() {
this._super(...arguments);
},
didRender() {
let self = this;
Mousetrap.bind('esc', function () {

View file

@ -15,6 +15,7 @@ import NotifierMixin from '../../mixins/notifier';
export default Ember.Controller.extend(NotifierMixin, {
documentService: Ember.inject.service('document'),
templateService: Ember.inject.service('template'),
sectionService: Ember.inject.service('section'),
page: null,
folder: {},
pages: [],
@ -188,6 +189,14 @@ export default Ember.Controller.extend(NotifierMixin, {
});
},
onDeleteBlock(blockId) {
this.get('sectionService').deleteBlock(blockId).then(() => {
this.audit.record("deleted-block");
this.send("showNotification", "Deleted");
this.transitionToRoute('document.index');
});
},
onDocumentDelete() {
this.get('documentService').deleteDocument(this.get('model.document.id')).then(() => {
this.audit.record("deleted-page");

View file

@ -2,7 +2,7 @@
{{#layout/zone-sidebar}}
{{document/document-sidebar document=model.document folder=model.folder pages=model.pages page=model.page isEditor=model.isEditor sections=model.sections
onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock') changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') gotoPage=(action 'gotoPage')}}
onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock') onDeleteBlock=(action 'onDeleteBlock') changePageSequence=(action 'onPageSequenceChange') changePageLevel=(action 'onPageLevelChange') gotoPage=(action 'gotoPage')}}
{{/layout/zone-sidebar}}
{{#layout/zone-content}}

View file

@ -81,6 +81,9 @@ export default BaseService.extend({
return this.get('ajax').post(url, {
data: JSON.stringify(payload),
contentType: 'json'
}).then((response) => {
let data = this.get('store').normalize('block', response);
return this.get('store').push(data);
});
},
@ -116,5 +119,14 @@ export default BaseService.extend({
method: 'PUT',
data: JSON.stringify(block)
});
},
// Removes specified reusable content block.
deleteBlock: function (blockId) {
let url = `sections/blocks/${blockId}`;
return this.get('ajax').request(url, {
method: 'DELETE'
});
}
});

View file

@ -83,17 +83,11 @@
text-align: center;
width: 20px;
margin-top: 5px;
opacity: 0.3;
opacity: 0.4;
> .material-icons, a {
color: $color-gray;
&:hover {
opacity: 1;
color: $color-primary;
}
}
}
}
}

View file

@ -26,6 +26,6 @@
{{/if}}
{{#if showSections}}
{{document/page-wizard display='section' document=document folder=folder sections=sections blocks=blocks
onCancel=(action 'onCancel') onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock')}}
onCancel=(action 'onCancel') onAddSection=(action 'onAddSection') onInsertBlock=(action 'onInsertBlock') onDeleteBlock=(action 'onDeleteBlock')}}
{{/if}}
</div>

View file

@ -40,9 +40,15 @@
<i class="material-icons">mode_edit</i>
{{/link-to}}
<div class="divider"></div>
<i class="material-icons">delete</i>
<i class="material-icons" id={{block.deleteId}}>delete</i>
</div>
<div class="clearfix" />
{{#dropdown-dialog target=block.deleteId position="top right" button="Delete" color="flat-red" onAction=(action 'onDeleteBlock' block.id)}}
<p>
Are you sure you want to delete block<br/>
<span class="bold">{{block.title}}?</span>
</p>
{{/dropdown-dialog}}
</li>
{{/each}}
</ul>

View file

@ -219,6 +219,7 @@ func init() {
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/space/{folderID}", []string{"GET", "OPTIONS"}, nil, GetBlocksForSpace))
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"GET", "OPTIONS"}, nil, GetBlock))
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"PUT", "OPTIONS"}, nil, UpdateBlock))
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks/{blockID}", []string{"DELETE", "OPTIONS"}, nil, DeleteBlock))
log.IfErr(Add(RoutePrefixPrivate, "sections/blocks", []string{"POST", "OPTIONS"}, nil, AddBlock))
// Links

View file

@ -226,7 +226,19 @@ func AddBlock(w http.ResponseWriter, r *http.Request) {
log.IfErr(tx.Commit())
writeSuccessEmptyJSON(w)
b, err = p.GetBlock(b.RefID)
if err != nil {
writeGeneralSQLError(w, method, err)
return
}
json, err := json.Marshal(b)
if err != nil {
writeJSONMarshalError(w, method, "block", err)
return
}
writeSuccessBytes(w, json)
}
// GetBlock returns requested reusable content block.
@ -337,3 +349,43 @@ func UpdateBlock(w http.ResponseWriter, r *http.Request) {
writeSuccessEmptyJSON(w)
}
// DeleteBlock removes requested reusable content block.
func DeleteBlock(w http.ResponseWriter, r *http.Request) {
method := "DeleteBlock"
p := request.GetPersister(r)
params := mux.Vars(r)
blockID := params["blockID"]
if len(blockID) == 0 {
writeMissingDataError(w, method, "blockID")
return
}
tx, err := request.Db.Beginx()
if err != nil {
writeTransactionError(w, method, err)
return
}
p.Context.Transaction = tx
_, err = p.DeleteBlock(blockID)
if err != nil {
log.IfErr(tx.Rollback())
writeGeneralSQLError(w, method, err)
return
}
err = p.RemoveBlockReference(blockID)
if err != nil {
log.IfErr(tx.Rollback())
writeGeneralSQLError(w, method, err)
return
}
log.IfErr(tx.Commit())
writeSuccessEmptyJSON(w)
}

View file

@ -12,6 +12,7 @@
package request
import (
"database/sql"
"fmt"
"time"
@ -113,6 +114,30 @@ func (p *Persister) DecrementBlockUsage(id string) (err error) {
return
}
// RemoveBlockReference clears page.blockid for given blockID.
func (p *Persister) RemoveBlockReference(id string) (err error) {
stmt, err := p.Context.Transaction.Preparex("UPDATE page SET blockid='', revised=? WHERE orgid=? AND blockid=?")
defer utility.Close(stmt)
if err != nil {
log.Error(fmt.Sprintf("Unable to prepare update RemoveBlockReference id %s", id), err)
return
}
_, err = stmt.Exec(time.Now().UTC(), p.Context.OrgID, id)
// skip no rows affected
if err == sql.ErrNoRows {
return
}
if err != nil {
log.Error(fmt.Sprintf("Unable to execute RemoveBlockReference id %s", id), err)
return
}
return
}
// UpdateBlock updates existing reusable content block item.
func (p *Persister) UpdateBlock(b entity.Block) (err error) {
b.Revised = time.Now().UTC()