From 466f43511604c566187203243b8784fe42ef8e5a Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Tue, 10 Aug 2021 13:46:37 +0200 Subject: [PATCH 1/4] Add rails admin link to inbox entries --- app/views/inbox/_entry.haml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index 216c61ee..7e1ffa94 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -19,6 +19,9 @@ = t 'views.actions.answer' %button.btn.btn-danger{ name: 'ib-destroy', data: { ib_id: i.id } } = t 'views.actions.delete' + - if current_user.has_role? :administrator + %a.btn.btn-primary{ href: rails_admin_path_for_resource(i) } + View in Kontrollzentrum %button.btn.btn-default{ name: 'ib-options', data: { ib_id: i.id, state: :hidden } } %i.fa.fa-cog %span.sr-only= t 'views.actions.options' From 77ec8e2f4bf3b30e86992bf3e4c0750236d6f02f Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 11 Aug 2021 14:10:24 +0200 Subject: [PATCH 2/4] Add report button to answerboxes --- app/javascript/packs/application.ts | 2 ++ app/javascript/retrospring/features/inbox/index.ts | 14 ++++++++++++++ .../retrospring/features/inbox/report.ts | 4 ++++ .../retrospring/utilities/registerEvents.ts | 2 +- app/views/inbox/_entry.haml | 3 +++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 app/javascript/retrospring/features/inbox/index.ts create mode 100644 app/javascript/retrospring/features/inbox/report.ts diff --git a/app/javascript/packs/application.ts b/app/javascript/packs/application.ts index bcfeddc4..91272b03 100644 --- a/app/javascript/packs/application.ts +++ b/app/javascript/packs/application.ts @@ -1,5 +1,7 @@ import start from '../retrospring/common'; import initAnswerbox from '../retrospring/features/answerbox/index'; +import initInbox from '../retrospring/features/inbox/index'; start(); document.addEventListener('turbolinks:load', initAnswerbox); +document.addEventListener('turbolinks:load', initInbox); \ No newline at end of file diff --git a/app/javascript/retrospring/features/inbox/index.ts b/app/javascript/retrospring/features/inbox/index.ts new file mode 100644 index 00000000..4c4af9b3 --- /dev/null +++ b/app/javascript/retrospring/features/inbox/index.ts @@ -0,0 +1,14 @@ +import registerEvents from "retrospring/utilities/registerEvents"; +import {reportEventHandler} from "./report"; + +export default (): void => { + const entries: NodeList = document.querySelectorAll('.inbox-entry:not(.js-initialized)'); + + entries.forEach((element: HTMLElement) => { + registerEvents([ + {type: 'click', target: element.querySelector('[name=ib-report]'), handler: reportEventHandler} + ]); + + element.classList.add('js-initialized'); + }); +} diff --git a/app/javascript/retrospring/features/inbox/report.ts b/app/javascript/retrospring/features/inbox/report.ts new file mode 100644 index 00000000..1c3f6b31 --- /dev/null +++ b/app/javascript/retrospring/features/inbox/report.ts @@ -0,0 +1,4 @@ +export function reportEventHandler(event: Event): void { + const element = event.target as HTMLElement; + window['reportDialog']('question', element.dataset.qId); +} \ No newline at end of file diff --git a/app/javascript/retrospring/utilities/registerEvents.ts b/app/javascript/retrospring/utilities/registerEvents.ts index a0991cce..4ff6edfa 100644 --- a/app/javascript/retrospring/utilities/registerEvents.ts +++ b/app/javascript/retrospring/utilities/registerEvents.ts @@ -1,4 +1,4 @@ -interface EventDef { +export interface EventDef { type: string; target: Node | NodeList; handler: EventListenerOrEventListenerObject; diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index 7e1ffa94..575c73ee 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -19,6 +19,9 @@ = t 'views.actions.answer' %button.btn.btn-danger{ name: 'ib-destroy', data: { ib_id: i.id } } = t 'views.actions.delete' + - if i.question.user_id != current_user.id + %button.btn.btn-primary{ name: 'ib-report', data: { q_id: i.question.id } } + = t 'views.actions.report' - if current_user.has_role? :administrator %a.btn.btn-primary{ href: rails_admin_path_for_resource(i) } View in Kontrollzentrum From 649bacfc453e07352546b27504e2afb098c64560 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 11 Aug 2021 22:35:07 +0200 Subject: [PATCH 3/4] Move report and rails admin buttons to a dropdown menu in the card header --- app/views/inbox/_entry.haml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index 575c73ee..a92cdfa7 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -12,6 +12,20 @@ %a{ href: show_user_question_path(i.question.user.screen_name, i.question.id) } = pluralize(i.question.answer_count, t('views.inbox.entry.response')) %p.answerbox__question-text= i.question.content + .pull-right + .btn-group + %button.btn.btn-default.btn-sm.dropdown-toggle{ data: { toggle: :dropdown }, aria: { expanded: false } } + %span.caret + .dropdown-menu.dropdown-menu-right{ role: :menu } + - if i.question.user_id != current_user.id + %a.dropdown-item{ name: 'ib-report', data: { q_id: i.question.id } } + %i.fa.fa-warning + = t 'views.actions.report' + - if current_user.has_role? :administrator + %a.dropdown-item{ href: rails_admin_path_for_resource(i) } + %i.fa.fa-gears + View in Kontrollzentrum + .card-body %textarea.form-control{ name: 'ib-answer', placeholder: t('views.placeholder.inbox'), data: { id: i.id } } %br/ @@ -19,12 +33,6 @@ = t 'views.actions.answer' %button.btn.btn-danger{ name: 'ib-destroy', data: { ib_id: i.id } } = t 'views.actions.delete' - - if i.question.user_id != current_user.id - %button.btn.btn-primary{ name: 'ib-report', data: { q_id: i.question.id } } - = t 'views.actions.report' - - if current_user.has_role? :administrator - %a.btn.btn-primary{ href: rails_admin_path_for_resource(i) } - View in Kontrollzentrum %button.btn.btn-default{ name: 'ib-options', data: { ib_id: i.id, state: :hidden } } %i.fa.fa-cog %span.sr-only= t 'views.actions.options' From c90daf17564fc152a90bc97706d4bec5e86d004a Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 11 Aug 2021 22:38:53 +0200 Subject: [PATCH 4/4] Skip inbox entry actions menu if it's be empty --- app/views/inbox/_entry.haml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/views/inbox/_entry.haml b/app/views/inbox/_entry.haml index a92cdfa7..ae46e93a 100644 --- a/app/views/inbox/_entry.haml +++ b/app/views/inbox/_entry.haml @@ -12,19 +12,20 @@ %a{ href: show_user_question_path(i.question.user.screen_name, i.question.id) } = pluralize(i.question.answer_count, t('views.inbox.entry.response')) %p.answerbox__question-text= i.question.content - .pull-right - .btn-group - %button.btn.btn-default.btn-sm.dropdown-toggle{ data: { toggle: :dropdown }, aria: { expanded: false } } - %span.caret - .dropdown-menu.dropdown-menu-right{ role: :menu } - - if i.question.user_id != current_user.id - %a.dropdown-item{ name: 'ib-report', data: { q_id: i.question.id } } - %i.fa.fa-warning - = t 'views.actions.report' - - if current_user.has_role? :administrator - %a.dropdown-item{ href: rails_admin_path_for_resource(i) } - %i.fa.fa-gears - View in Kontrollzentrum + - if i.question.user_id != current_user.id || current_user.has_role?(:administrator) + .pull-right + .btn-group + %button.btn.btn-default.btn-sm.dropdown-toggle{ data: { toggle: :dropdown }, aria: { expanded: false } } + %span.caret + .dropdown-menu.dropdown-menu-right{ role: :menu } + - if i.question.user_id != current_user.id + %a.dropdown-item{ name: 'ib-report', data: { q_id: i.question.id } } + %i.fa.fa-warning + = t 'views.actions.report' + - if current_user.has_role? :administrator + %a.dropdown-item{ href: rails_admin_path_for_resource(i) } + %i.fa.fa-gears + View in Kontrollzentrum .card-body %textarea.form-control{ name: 'ib-answer', placeholder: t('views.placeholder.inbox'), data: { id: i.id } }