Convert export-modal into OpModalComponet

pull/6275/head
Oliver Günther 7 years ago
parent c790aeda29
commit 576554e2d9
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 3
      frontend/app/angular4-modules.ts
  2. 82
      frontend/app/components/modals/export-modal/export-modal.controller.ts
  3. 24
      frontend/app/components/modals/export-modal/export-modal.service.html
  4. 40
      frontend/app/components/modals/export-modal/export-modal.service.ts
  5. 27
      frontend/app/components/modals/export-modal/wp-table-export.modal.html
  6. 77
      frontend/app/components/modals/export-modal/wp-table-export.modal.ts
  7. 6
      frontend/app/components/op-context-menu/handlers/op-settings-dropdown-menu.directive.ts

@ -215,6 +215,7 @@ import {NotificationsContainerComponent} from 'core-components/common/notificati
import {UploadProgressComponent} from 'core-components/common/notifications/upload-progress.component';
import {ExternalQueryConfigurationComponent} from 'core-components/wp-table/external-configuration/external-query-configuration.component';
import {ExternalQueryConfigurationService} from 'core-components/wp-table/external-configuration/external-query-configuration.service';
import {WpTableExportModal} from "core-components/modals/export-modal/wp-table-export.modal";
@NgModule({
imports: [
@ -442,6 +443,7 @@ import {ExternalQueryConfigurationService} from 'core-components/wp-table/extern
WpTableConfigurationSortByTab,
WpTableConfigurationTimelinesTab,
AttributeHelpTextModal,
WpTableExportModal,
// Notifications
NotificationsContainerComponent,
@ -504,6 +506,7 @@ import {ExternalQueryConfigurationService} from 'core-components/wp-table/extern
WpTableConfigurationSortByTab,
WpTableConfigurationTimelinesTab,
AttributeHelpTextModal,
WpTableExportModal,
// Notifications
NotificationsContainerComponent,

@ -1,82 +0,0 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
import {wpControllersModule} from '../../../angular-modules';
import {WorkPackageTableColumnsService} from '../../wp-fast-table/state/wp-table-columns.service';
import {TableState} from 'core-components/wp-table/table-state/table-state';
import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';
import {HalLink} from 'core-app/modules/hal/hal-link/hal-link';
interface ExportLink extends HalLink {
identifier:string;
}
class ExportModalController {
public name:string;
public closeMe:Function;
public exportOptions:any;
constructor(exportModal:any,
private UrlParamsHelper:any,
private tableState:TableState,
private wpTableColumns:WorkPackageTableColumnsService) {
var results = this.tableState.results.value!;
this.name = 'Export';
this.closeMe = exportModal.deactivate;
this.exportOptions = this.buildExportOptions(results);
}
public $onInit() {
// Created for interface compliance
}
private buildExportOptions(results:WorkPackageCollectionResource) {
return results.representations.map(format => {
const link = format.$link as ExportLink;
return {
identifier: link.identifier,
label: link.title,
url: this.addColumnsToHref(format.href!)
};
});
}
private addColumnsToHref(href:string) {
let columns = this.wpTableColumns.getColumns();
let columnIds = columns.map(function (column) {
return column.id;
});
return href + "&" + this.UrlParamsHelper.buildQueryString({ 'columns[]': columnIds });
}
}
wpControllersModule.controller('ExportModalController', ExportModalController);

@ -1,24 +0,0 @@
<div class="ng-modal-window">
<div class="ng-modal-inner">
<div class="modal-header">
<a>
<i
class="icon-close"
ng-click="$ctrl.closeMe()"
title="{{ ::I18n.t('js.close_popup_title') }}">
</i>
</a>
</div>
<h3>{{ ::I18n.t('js.label_export') }}</h3>
<ul class="export-options">
<li ng-repeat="option in $ctrl.exportOptions">
<a ng-href="{{ ::option.url }}" focus="$first" id="export-{{ ::option.identifier }}">
<op-icon icon-classes="icon-export-{{ ::option.identifier }} icon-big"></op-icon>
<span class="export-label">{{ ::option.label }}</span>
</a>
</li>
</ul>
</div>
</div>

@ -1,40 +0,0 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
import {wpControllersModule} from '../../../angular-modules';
function exportModalService(btfModal:any) {
return btfModal({
controller: 'ExportModalController',
controllerAs: '$ctrl',
afterFocusOn: '#work-packages-settings-button',
templateUrl: '/components/modals/export-modal/export-modal.service.html'
});
}
wpControllersModule.factory('exportModal', exportModalService);

@ -0,0 +1,27 @@
<div class="op-modal--container ng-modal-window">
<div class="ng-modal-inner wp-table--configuration-modal loading-indicator--location"
data-indicator-name="modal"
tabindex="0">
<div class="modal-header">
<a>
<i
class="icon-close"
(click)="closeMe($event)"
[attr.title]="text.closePopup">
</i>
</a>
</div>
<h3 [textContent]="text.title"></h3>
<ul *ngIf="exportOptions" class="export-options">
<li *ngFor="let option of exportOptions">
<a [attr.href]="option.url"
id="export-{{ option.identifier }}">
<op-icon icon-classes="icon-export-{{ option.identifier }} icon-big"></op-icon>
<span class="export-label" [textContent]="option.label"></span>
</a>
</li>
</ul>
</div>
</div>

@ -0,0 +1,77 @@
import {Component, ElementRef, Inject, OnInit} from '@angular/core';
import {I18nToken, OpModalLocalsToken} from 'core-app/angular4-transition-utils';
import {OpModalLocalsMap} from 'core-components/op-modals/op-modal.types';
import {WorkPackageTableColumnsService} from 'core-components/wp-fast-table/state/wp-table-columns.service';
import {OpModalComponent} from 'core-components/op-modals/op-modal.component';
import {TableState} from 'core-components/wp-table/table-state/table-state';
import {UrlParamsHelperService} from "core-components/wp-query/url-params-helper";
import {WorkPackageCollectionResource} from "core-app/modules/hal/resources/wp-collection-resource";
import {HalLink} from "core-app/modules/hal/hal-link/hal-link";
interface ExportLink extends HalLink {
identifier:string;
}
@Component({
template: require('!!raw-loader!./wp-table-export.modal.html')
})
export class WpTableExportModal extends OpModalComponent implements OnInit {
/* Close on escape? */
public closeOnEscape = true;
/* Close on outside click */
public closeOnOutsideClick = true;
public $element:JQuery;
public exportOptions:{ identifier:string, label:string, url:string }[];
public text = {
title: this.I18n.t('js.label_export'),
closePopup: this.I18n.t('js.close_popup_title'),
};
constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
@Inject(I18nToken) readonly I18n:op.I18n,
readonly elementRef:ElementRef,
readonly UrlParamsHelper:UrlParamsHelperService,
readonly tableState:TableState,
readonly wpTableColumns:WorkPackageTableColumnsService) {
super(locals, elementRef);
}
ngOnInit() {
this.$element = jQuery(this.elementRef.nativeElement);
this.tableState.results
.valuesPromise()
.then((results) => this.exportOptions = this.buildExportOptions(results!));
}
private buildExportOptions(results:WorkPackageCollectionResource) {
return results.representations.map(format => {
const link = format.$link as ExportLink;
return {
identifier: link.identifier,
label: link.title,
url: this.addColumnsToHref(format.href!)
};
});
}
private addColumnsToHref(href:string) {
let columns = this.wpTableColumns.getColumns();
let columnIds = columns.map(function (column) {
return column.id;
});
return href + "&" + this.UrlParamsHelper.buildQueryString({ 'columns[]': columnIds });
}
protected get afterFocusOn():JQuery {
return jQuery('#work-packages-settings-button');
}
}

@ -43,6 +43,8 @@ import {componentDestroyed} from 'ng2-rx-componentdestroyed';
import {takeUntil} from 'rxjs/operators';
import {QueryFormResource} from 'core-app/modules/hal/resources/query-form-resource';
import {QueryResource} from 'core-app/modules/hal/resources/query-resource';
import {OpModalService} from "core-components/op-modals/op-modal.service";
import {WpTableExportModal} from "core-components/modals/export-modal/wp-table-export.modal";
@Directive({
selector: '[opSettingsContextMenu]'
@ -54,13 +56,13 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger implements OnD
constructor(readonly elementRef:ElementRef,
readonly opContextMenu:OPContextMenuService,
readonly opModalService:OpModalService,
readonly wpListService:WorkPackagesListService,
readonly authorisationService:AuthorisationService,
readonly states:States,
@Inject(shareModalToken) readonly shareModal:any,
@Inject(saveModalToken) readonly saveModal:any,
@Inject(settingsModalToken) readonly settingsModal:any,
@Inject(exportModalToken) readonly exportModal:any,
@Inject(I18nToken) readonly I18n:op.I18n) {
super(elementRef, opContextMenu);
@ -197,7 +199,7 @@ export class OpSettingsMenuDirective extends OpContextMenuTrigger implements OnD
icon: 'icon-export',
onClick: ($event:JQueryEventObject) => {
if (this.allowWorkPackageAction($event, 'representations')) {
this.exportModal.activate();
this.opModalService.show(WpTableExportModal);
}
return true;

Loading…
Cancel
Save