diff --git a/app/components/viewer/action_buttons/index.hbs b/app/components/viewer/action_buttons/index.hbs index 8ca8a63a669a9bc4200a0f6c93ff498305ea944c..7768236d7734d49482359ed4fc7ef64bf842f1ed 100644 --- a/app/components/viewer/action_buttons/index.hbs +++ b/app/components/viewer/action_buttons/index.hbs @@ -20,6 +20,20 @@ </button> {{/if}} {{#if this.is_any_page_selected }} + <button + class="btn btn-light" + type="button" + {{on "click" @onRotateClockwise}} > + <i class="bi bi-arrow-clockwise"></i> + Rotate + </button> + <button + class="btn btn-light" + type="button" + {{on "click" @onRotateCounterclockwise}} > + <i class="bi bi-arrow-counterclockwise"></i> + Rotate + </button> <button class="btn btn-danger mx-5" type="button" diff --git a/app/components/viewer/index.hbs b/app/components/viewer/index.hbs index 33b1f8b70a365211fa0296641f10587034ed08c2..9a506cdb219356ef459f88bcd521406e6021c7d6 100644 --- a/app/components/viewer/index.hbs +++ b/app/components/viewer/index.hbs @@ -6,6 +6,8 @@ @ocrStatus={{this.ocrStatus}} @selectedPages={{this.selected_pages}} @openConfirmDeletionModal={{this.openConfirmDeletionModal}} + @onRotateClockwise={{this.onRotateClockwise}} + @onRotateCounterclockwise={{this.onRotateCounterclockwise}} @onRunOCR={{this.onRunOCR}} /> <Viewer::ActionModes diff --git a/app/components/viewer/index.js b/app/components/viewer/index.js index d53b6af36d292686f41fd1f5c062faa3ecaf213b..e821fd596dd4fce6ac65424417ea27a7031df50e 100644 --- a/app/components/viewer/index.js +++ b/app/components/viewer/index.js @@ -104,6 +104,32 @@ export default class ViewerComponent extends Component { }); } + @action + async onRotateClockwise() { + let page_ids = []; + + page_ids = this.selected_pages.map(page => page.id); + await this.requests.rotatePages({ + page_ids: page_ids, + angle: 90 + }); + this.selected_pages = A([]); + this.router.refresh(); + } + + @action + async onRotateCounterclockwise() { + let page_ids = []; + + page_ids = this.selected_pages.map(page => page.id); + await this.requests.rotatePages({ + page_ids: page_ids, + angle: 270 + }); + this.selected_pages = A([]); + this.router.refresh(); + } + @action onNodeClicked() { } diff --git a/app/components/viewer/thumbnail/index.js b/app/components/viewer/thumbnail/index.js index 57474a26c6908f6994d3a4d8822fae18b8961c0c..c4d9bb0e872a2ea430c280d566291c8c01465bee 100644 --- a/app/components/viewer/thumbnail/index.js +++ b/app/components/viewer/thumbnail/index.js @@ -37,4 +37,8 @@ export default class ViewerThumbnailComponent extends Component { return false; } + + set is_selected(value) { + + } } \ No newline at end of file diff --git a/app/services/requests.js b/app/services/requests.js index 2c4ea02cd9ed272581cd0e256ba1b62954e1ef6a..ef82def1559d79218b8dd6f704814beccc0ffcf2 100644 --- a/app/services/requests.js +++ b/app/services/requests.js @@ -37,6 +37,15 @@ export default class Requests extends Service { return this._delete('/pages/', {'pages': page_ids}); } + async rotatePages({page_ids, angle}) { + let pages = []; + + pages = page_ids.map(page_id => { + return {id: page_id, angle: angle}; + }); + return this._post('/pages/rotate/', {'pages': pages}); + } + /** * `document_version` contains following attributes: * id @@ -154,7 +163,25 @@ export default class Requests extends Service { }); } + async _post(url, data) { + return this._generic({ + method: 'POST', + url: url, + data: data, + content_type: 'application/json' + }); + } + async _delete(url, data) { + return this._generic({ + method: 'DELETE', + url: url, + data: data, + content_type: 'application/json' + }); + } + + async _generic({method, url, data, content_type}) { let url_with_base, body_data = '', headers_copy = {}; @@ -162,14 +189,14 @@ export default class Requests extends Service { url_with_base = `${base_url()}${url}`; Object.assign(headers_copy, this.headers); - headers_copy['Content-Type'] = 'application/json'; + headers_copy['Content-Type'] = content_type; if (data) { body_data = JSON.stringify(data); } return fetch(url_with_base, { - method: 'DELETE', + method: method, headers: headers_copy, body: body_data, });