Skip to content

Commit

Permalink
Merge pull request #820 from kanselarij-vlaanderen/feature/KAS-261-re…
Browse files Browse the repository at this point in the history
…factor-publications-index-route

Feature/kas 261 refactor publications index route
  • Loading branch information
erikap authored Apr 9, 2021
2 parents de454cd + 57a64c7 commit 7fed30e
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 152 deletions.
59 changes: 0 additions & 59 deletions app/pods/publications/controller.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,5 @@
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import PublicationFilter from 'frontend-kaleidos/utils/publication-filter';

export default class PublicationsController extends Controller {
@service publicationService;
@service('-routing') routing;
@tracked isShowPublicationModal = false;
@tracked showLoader = false;
@tracked isShowPublicationFilterModal = false;

@tracked publicationFilter = new PublicationFilter(JSON.parse(localStorage.getItem('publicationFilter')) || {});

@action
async startPublicationFromCaseId(_caseId) {
this.showLoader = true;
const newPublicationNumber = await this.publicationService.getNewPublicationNextNumber();
const newPublication = await this.publicationService.createNewPublication(newPublicationNumber, '', _caseId);
this.showLoader = false;

this.transitionToRoute('publications.publication.case', newPublication.get('id'));
}

@action
showPublicationModal() {
this.isShowPublicationModal = true;
}

@action
closePublicationModal() {
this.isShowPublicationModal = false;
}

@action
async saveNewPublication(publication) {
const newPublication = await this.publicationService.createNewPublication(publication.number, publication.suffix, false, publication.longTitle, publication.shortTitle);
this.closePublicationModal();
this.transitionToRoute('publications.publication', newPublication.get('id'));
}

@action
showFilterModal() {
this.isShowPublicationFilterModal = true;
}

@action
cancelPublicationsFilter() {
this.isShowPublicationFilterModal = false;
}

@action
savePublicationsFilter(publicationFilter) {
this.publicationFilter = publicationFilter;
localStorage.setItem('publicationFilter', this.publicationFilter.toString());
this.isShowPublicationFilterModal = false;
this.send('refreshModel');
}

get shouldShowPublicationHeader() {
return this.routing.currentRouteName.startsWith('publications.index');
}
}
60 changes: 57 additions & 3 deletions app/pods/publications/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import tableColumns from 'frontend-kaleidos/config/publications/overview-table-columns';
import PublicationFilter from 'frontend-kaleidos/utils/publication-filter';

export default class PublicationsIndexController extends Controller {
queryParams = {
Expand All @@ -16,6 +18,11 @@ export default class PublicationsIndexController extends Controller {
},
};

@service publicationService;

page = 0;
size = 25;
sort = '-created';
sizeOptions = Object.freeze([5, 10, 25, 50, 100, 200]);

@tracked tableColumnDisplayOptions = JSON.parse(localStorage.getItem('tableColumnDisplayOptions'))
Expand All @@ -26,9 +33,11 @@ export default class PublicationsIndexController extends Controller {
tableColumns = tableColumns;

@tracked showTableDisplayOptions = false;
@tracked page = 0;
@tracked size = 25;
@tracked sort = '-created';
@tracked isShowPublicationModal = false;
@tracked showLoader = false;
@tracked isShowPublicationFilterModal = false;

@tracked publicationFilter = new PublicationFilter(JSON.parse(localStorage.getItem('publicationFilter')) || {});

@action
navigateToPublication(publicationFlowRow) {
Expand Down Expand Up @@ -56,4 +65,49 @@ export default class PublicationsIndexController extends Controller {
closeColumnDisplayOptionsModal() {
this.showTableDisplayOptions = false;
}

@action
async startPublicationFromCaseId(_caseId) {
this.showLoader = true;
const newPublicationNumber = await this.publicationService.getNewPublicationNextNumber();
const newPublication = await this.publicationService.createNewPublication(newPublicationNumber, '', _caseId);
this.showLoader = false;

this.transitionToRoute('publications.publication.case', newPublication.get('id'));
}

@action
showPublicationModal() {
this.isShowPublicationModal = true;
}

@action
closePublicationModal() {
this.isShowPublicationModal = false;
}

@action
async saveNewPublication(publication) {
const newPublication = await this.publicationService.createNewPublication(publication.number, publication.suffix, false, publication.longTitle, publication.shortTitle);
this.closePublicationModal();
this.transitionToRoute('publications.publication', newPublication.get('id'));
}

@action
showFilterModal() {
this.isShowPublicationFilterModal = true;
}

@action
cancelPublicationsFilter() {
this.isShowPublicationFilterModal = false;
}

@action
savePublicationsFilter(publicationFilter) {
this.publicationFilter = publicationFilter;
localStorage.setItem('publicationFilter', this.publicationFilter.toString());
this.isShowPublicationFilterModal = false;
this.send('refreshModel');
}
}
35 changes: 13 additions & 22 deletions app/pods/publications/index/route.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import CONFIG from 'frontend-kaleidos/utils/config';
import { dasherize } from '@ember/string';
import PublicationFilter from 'frontend-kaleidos/utils/publication-filter';

export default class PublicationsIndexRoute extends Route.extend(AuthenticatedRouteMixin) {
export default class PublicationsIndexRoute extends Route {
queryParams = {
page: {
refreshModel: true,
Expand All @@ -21,30 +20,33 @@ export default class PublicationsIndexRoute extends Route.extend(AuthenticatedRo
},
}

beforeModel() {
this.publicationFilter = new PublicationFilter(JSON.parse(localStorage.getItem('publicationFilter')) || {});
}

async model(params) {
const publicationFilter = new PublicationFilter(JSON.parse(localStorage.getItem('publicationFilter')) || {});
const ids = [];
let ministerFilter = {};

if (publicationFilter.publishedFilterOption) {
if (this.publicationFilter.publishedFilterOption) {
ids.push(CONFIG.publicationStatusPublished.id);
}
if (publicationFilter.pausedFilterOption) {
if (this.publicationFilter.pausedFilterOption) {
ids.push(CONFIG.publicationStatusPauzed.id);
}
if (publicationFilter.withdrawnFilterOption) {
if (this.publicationFilter.withdrawnFilterOption) {
ids.push(CONFIG.publicationStatusWithdrawn.id);
}
if (publicationFilter.toPublishFilterOption) {
if (this.publicationFilter.toPublishFilterOption) {
ids.push(CONFIG.publicationStatusToPublish.id);
}
if (!(publicationFilter.ministerFilterOption && publicationFilter.notMinisterFilterOption)) {
if (publicationFilter.ministerFilterOption) {
if (!(this.publicationFilter.ministerFilterOption && this.publicationFilter.notMinisterFilterOption)) {
if (this.publicationFilter.ministerFilterOption) {
ministerFilter = {
':has:subcases': 'yes',
};
}
if (publicationFilter.notMinisterFilterOption) {
if (this.publicationFilter.notMinisterFilterOption) {
ministerFilter = {
':has-no:subcases': 'yes',
};
Expand Down Expand Up @@ -77,7 +79,7 @@ export default class PublicationsIndexRoute extends Route.extend(AuthenticatedRo
}
// note that the "dasherize" here is used in order to keep the original column keyName's
if (qpSort === dasherize('publicationNumber')) {
// Specifically requested by Johan, because Suffix needs to be string and Quater...
// show the most recent publication first if publication-number is the same
apiSort = 'publication-number,-created';
} else if (qpSort === dasherize('regulationType')) {
apiSort = 'regulation-type.position';
Expand Down Expand Up @@ -108,15 +110,4 @@ export default class PublicationsIndexRoute extends Route.extend(AuthenticatedRo
refreshModel() {
this.refresh();
}

@action
refresh() {
super.refresh();
}

setupController(controller, model) {
super.setupController(controller, model);
const params = this.paramsFor('publications.index');
controller.page = params.page;
}
}
54 changes: 53 additions & 1 deletion app/pods/publications/index/template.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,50 @@
{{!-- TODO auk-panel-layout gebruiken, component ? --}}
<div class="vlc-panel-layout__main-content">
<WebComponents::AuNavbar class="vlc-publication-overview-navbar" @border="bottom" @skin="gray-100" @auto="true">
<WebComponents::AuToolbar>
<WebComponents::AuToolbar::Group @position="left">
<WebComponents::AuToolbar::Item>
<div class="auk-u-flex auk-u-flex--vertical auk-u-mt-2">
<h4 class="auk-toolbar-complex__title">{{t "publications" }}</h4>
</div>
</WebComponents::AuToolbar::Item>
</WebComponents::AuToolbar::Group>
<WebComponents::AuToolbar::Group @position="right">
<WebComponents::AuToolbar::Item>
<WebComponents::AuDropdown>
<Publications::PublicationCaseSearch />
</WebComponents::AuDropdown>
</WebComponents::AuToolbar::Item>
<WebComponents::AuToolbar::Item>
<WebComponents::AuButton @skin="secondary" @icon="filter" {{on "click" (fn this.showFilterModal)}}>
{{t "filter-content"}}
</WebComponents::AuButton>
</WebComponents::AuToolbar::Item>

<WebComponents::AuToolbar::Item>
<WebComponents::AuButton data-test-publication-header-button-new @icon="add" @skin="primary" {{on "click"
(fn this.showPublicationModal)}}>
{{t "publications-new"}}
</WebComponents::AuButton>
</WebComponents::AuToolbar::Item>
</WebComponents::AuToolbar::Group>
</WebComponents::AuToolbar>
</WebComponents::AuNavbar>
<div class="vlc-u-box-model-maximize-height vlc-scroll-wrapper">
{{#if this.isShowPublicationModal}}
<Publications::NewPublicationModal
@onCancel={{this.closePublicationModal}}
@onSave={{this.saveNewPublication}} />
{{/if}}
{{#if this.isShowPublicationFilterModal}}
<Publications::PublicationsFilterModal
@filter={{this.publicationFilter}}
@onCancel={{this.cancelPublicationsFilter}}
@onSave={{this.savePublicationsFilter}} />
{{/if}}
{{outlet}}
</div>
</div>
<div class="auk-u-m-2 auk-u-scroll-scrollable">
<WebComponents::AuButton @icon="settings" @skin="borderless" data-test-publication-button-filter-tables
{{on "click" this.openColumnDisplayOptionsModal}}
Expand Down Expand Up @@ -41,7 +88,7 @@
</c.header>
<c.body class="auk-table--interaction-cursor" as |row|>
{{#if this.tableColumnDisplayOptions.caseName}}
{{!-- There is legacy data were case does not have a shortTitle, we have to fall back to title --}}
{{!-- There is legacy data were case does not have a shortTitle, we have to fall back to title --}}
<td class="auk-table__col--6">
{{#if row.case.shortTitle}}
<WebComponents::AuAbbreviatedText @text={{row.case.shortTitle}} @size="150"/>
Expand Down Expand Up @@ -251,3 +298,8 @@
@onClose={{this.closeColumnDisplayOptionsModal}}
/>
{{/if}}

{{!-- LOADER --}}
{{#if this.showLoader}}
<WebComponents::AuLoadingOverlay />
{{/if}}
9 changes: 0 additions & 9 deletions app/pods/publications/route.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
import Route from '@ember/routing/route';
import { action } from '@ember/object';

export default class PublicationsRoute extends Route.extend(AuthenticatedRouteMixin) {
@action
refreshModel() {
this.refresh();
}

@action
refresh() {
super.refresh();
}
}
60 changes: 2 additions & 58 deletions app/pods/publications/template.hbs
Original file line number Diff line number Diff line change
@@ -1,58 +1,2 @@
{{ page-title
(t "publications")
}}
{{#if shouldShowPublicationHeader}}
{{!-- TODO auk-panel-layout gebruiken, component ? --}}
<div class="vlc-panel-layout__main-content">
<WebComponents::AuNavbar class="vlc-publication-overview-navbar" @border="bottom" @skin="gray-100" @auto="true">
<WebComponents::AuToolbar>
<WebComponents::AuToolbar::Group @position="left">
<WebComponents::AuToolbar::Item>
<div class="auk-u-flex auk-u-flex--vertical auk-u-mt-2">
<h4 class="auk-toolbar-complex__title">{{t "publications" }}</h4>
</div>
</WebComponents::AuToolbar::Item>
</WebComponents::AuToolbar::Group>
<WebComponents::AuToolbar::Group @position="right">
<WebComponents::AuToolbar::Item>
<WebComponents::AuDropdown>
<Publications::PublicationCaseSearch />
</WebComponents::AuDropdown>
</WebComponents::AuToolbar::Item>
<WebComponents::AuToolbar::Item>
<WebComponents::AuButton @skin="secondary" @icon="filter" {{on "click" (fn this.showFilterModal)}}>
{{t "filter-content"}}
</WebComponents::AuButton>
</WebComponents::AuToolbar::Item>

<WebComponents::AuToolbar::Item>
<WebComponents::AuButton data-test-publication-header-button-new @icon="add" @skin="primary" {{on "click"
(fn this.showPublicationModal)}}>
{{t "publications-new"}}
</WebComponents::AuButton>
</WebComponents::AuToolbar::Item>
</WebComponents::AuToolbar::Group>
</WebComponents::AuToolbar>
</WebComponents::AuNavbar>
<div class="vlc-u-box-model-maximize-height vlc-scroll-wrapper">
{{#if this.isShowPublicationModal}}
<Publications::NewPublicationModal
@onCancel={{this.closePublicationModal}}
@onSave={{this.saveNewPublication}} />
{{/if}}
{{#if this.isShowPublicationFilterModal}}
<Publications::PublicationsFilterModal
@filter={{this.publicationFilter}}
@onCancel={{this.cancelPublicationsFilter}}
@onSave={{this.savePublicationsFilter}} />
{{/if}}
{{outlet}}
</div>
</div>
{{else}}
{{outlet}}
{{/if}}
{{!-- LOADER --}}
{{#if this.showLoader}}
<WebComponents::AuLoadingOverlay />
{{/if}}
{{ page-title (t "publications") }}
{{outlet}}

0 comments on commit 7fed30e

Please sign in to comment.