Merge branch 'master' of code-repo.d4science.org:MaDgIK/openaire-library

This commit is contained in:
argirok 2021-12-17 11:41:52 +02:00
commit e58a2b0008
9 changed files with 367 additions and 109 deletions

View File

@ -32,12 +32,16 @@ export class CommunityService {
this.community.next(community);
}
getCommunityInfo(communityId: string) {
return this.http.get<CommunityInfo>(properties.communityAPI + communityId)
.pipe(map(community => this.parseCommunity(community)));
}
getCommunity(communityId: string, refresh = false) {
if (this.communityId !== communityId || !this.community.value || refresh) {
this.communityId = communityId;
this.promise = new Promise<any>((resolve, reject) => {
this.subs.push(this.http.get<CommunityInfo>(properties.communityAPI + communityId)
.pipe(map(community => this.parseCommunity(community))).subscribe(community => {
this.subs.push(this.getCommunityInfo(communityId).subscribe(community => {
this.community.next(community);
resolve();
},

View File

@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import {RouterModule} from '@angular/router';
import {MenuComponent} from "./menu.component";
@NgModule({
imports: [
RouterModule.forChild([
{ path: '',component: MenuComponent}
])
]
})
export class MenuRoutingModule { }

View File

@ -0,0 +1,130 @@
<div page-content class="admin-pages">
<div header>
<admin-tabs tab="menu" [portal]="portal"></admin-tabs>
<div *ngIf="!showLoading" class="uk-grid" uk-grid>
<div class="uk-width-1-1">
<ul *ngIf="!isPortalAdministrator" class="uk-subnav uk-subnav-pill uk-flex uk-flex-middle">
<li [class.uk-active]="filterForm.get('status').value === 'resources'" class="uk-visible-toggle uk-position-relative uk-padding-remove-horizontal">
<span>
<a (click)="filterForm.get('status').setValue('resources')">
<span class="title">Resourses</span>
</a>
<span class="uk-invisible-hover uk-position-center-right color">
<span class="clickable" uk-icon="more-vertical"></span>
<div #element uk-dropdown="mode: click; pos: bottom-right; offset: 10; delay-hide: 0; flip: false">
<ul class="uk-nav uk-dropdown-nav">
<li>
<a>Edit</a>
</li>
<hr class="uk-nav-divider">
<li>
<a>Delete</a>
</li>
</ul>
</div>
</span>
</span>
</li>
<li class="uk-visible-toggle">
<span class="clickable">
<span class="uk-icon-button small portal-icon-button">
<icon name="add"></icon>
</span>
<span class="space uk-hidden-hover">
Create new root menu
</span>
</span>
</li>
</ul>
</div>
</div>
<div class="uk-width-1-1 uk-flex uk-flex-right@m uk-flex-center uk-flex-wrap uk-flex-middle uk-grid uk-margin-remove-top" uk-grid>
<div #searchInputComponent search-input [control]="filterForm.controls.keyword" [showSearch]="false" placeholder="Search menu item"
[selected]="selectedKeyword" (closeEmitter)="onSearchClose()" (resetEmitter)="reset()"
[bordered]="true" colorClass="uk-text-secondary"
class="uk-width-1-3@xl uk-width-2-5@l uk-width-1-2@m uk-width-1-1"></div>
<div>
<a (click)="newMenuItem()" class="uk-flex uk-flex-middle uk-text-uppercase">
<button class="large uk-icon-button uk-button-secondary">
<icon name="add"></icon>
</button>
<button class="uk-button uk-button-link uk-margin-small-left uk-text-secondary">
Add new menu item
</button>
</a>
</div>
</div>
<!-- Not currently working -->
<div *ngIf="!showLoading && checkboxes.length > 0" class="uk-padding
uk-padding-remove-bottom uk-padding-remove-top uk-margin-remove-top uk-margin-small-bottom uk-display-inline"
[attr.uk-tooltip]="getSelectedMenuItems().length == 0 ? 'pos:left; cls: uk-active' : null"
title="Select at least one menu item">
<input id="checkAll" type="checkbox" (click)="selectAll()" [ngModel]="getSelectedMenuItems().length == checkboxes.length"/>
<span *ngIf="getSelectedMenuItems().length > 0" class="uk-margin-left uk-text-muted"> {{getSelectedMenuItems().length}} menu items selected </span>
<a class="uk-margin-left">Actions</a>
<div uk-dropdown="mode: click">
<ul class="uk-nav uk-dropdown-nav"
[attr.uk-tooltip]="getSelectedMenuItems().length == 0 ? 'pos:left; cls: uk-active' : 'cls: uk-invisible'"
title="Select at least one page">
<li *ngIf="!isPortalAdministrator"><a [class]="getSelectedMenuItems().length == 0 ? 'uk-disabled' : ''"
(click)="toggleMenuItems(true,getSelectedMenuItems())"><i></i> Enable
</a></li>
<li *ngIf="!isPortalAdministrator"><a [class]="getSelectedMenuItems().length == 0 ? 'uk-disabled' : ''"
(click)="toggleMenuItems(false,getSelectedMenuItems())"><i></i> Disable
</a>
</li>
<li *ngIf="isPortalAdministrator"><a [class]="getSelectedMenuItems().length == 0 ? 'uk-disabled' : ''"
(click)="confirmDeleteSelectedMenuItems()"><i></i> Delete </a></li>
</ul>
</div>
</div>
</div>
<div inner>
<div *ngIf="showLoading" class="uk-position-center">
<loading></loading>
</div>
<div *ngIf="!showLoading">
<ul class="uk-list submenu-items">
<li class="uk-card uk-card-default uk-margin-bottom">
<div class="uk-grid uk-grid-divider uk-padding" uk-grid>
<div class="uk-width-4-5">
<div class="uk-grid uk-flex uk-flex-middle">
<div>
<input type="checkbox" id="" class="checkBox" name="" value="">
</div>
<div class="uk-width-expand uk-margin-medium-bottom">
Name and info
</div>
<div class="uk-grid uk-width-1-1 uk-margin-left">
Additional info
</div>
</div>
</div>
<div class="uk-width-1-5">
<div class="uk-flex uk-flex-center">
<div href="#" class="actions">
<div class="uk-button action uk-margin-top uk-flex uk-flex-middle" (click)="editMenuItem()">
<i uk-icon="pencil" class="clickable uk-icon"></i>
<span class="uk-margin-small-left"> Edit</span>
</div>
<div class="uk-button action uk-margin-top uk-flex uk-flex-middle" (click)="deleteMenuItem()">
<i uk-icon="trash" class="clickable uk-icon"></i>
<span class="uk-margin-small-left"> Delete</span>
</div>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
<modal-alert #editModal [okDisabled]="menuItemForm && (menuItemForm.invalid || menuItemForm.dirty)">
<form *ngIf="menuItemForm" [formGroup]="menuItemForm" class="uk grid uk-child-width-1-1" uk-grid>
<div dashboard-input [formInput]="menuItemForm.get('name')" type="text" label="Name" placeholder="Write a name"></div>
<div dashboard-input [formInput]="menuItemForm.get('type')" type="select" label="Type" placeholder="Choose a type" [options]="typeOptions"></div>
<div dashboard-input [formInput]="menuItemForm.get('route')" type="text" label="Route" placeholder="Write a route"></div>
<div dashboard-input [formInput]="menuItemForm.get('url')" type="text" label="URL" placeholder="Write a URL"></div>
</form>
</modal-alert>

View File

@ -0,0 +1,172 @@
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {HelpContentService} from '../../services/help-content.service';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {Portal} from '../../utils/entities/adminTool/portal';
import {EnvProperties} from '../../utils/properties/env-properties';
import {Session} from '../../login/utils/helper.class';
import {UserManagementService} from '../../services/user-management.service';
import {Subscriber} from "rxjs";
import {properties} from "../../../../environments/environment";
import {StringUtils} from "../../utils/string-utils.class";
import {Title} from "@angular/platform-browser";
import {AlertModal} from '../../utils/modal/alert';
import {CheckMenuItem, MenuItem} from '../../sharedComponents/menu';
import {SearchInputComponent} from '../../sharedComponents/search-input/search-input.component';
@Component({
selector: 'menuSelector',
templateUrl: './menu.component.html',
})
export class MenuComponent implements OnInit {
@ViewChild('searchInputComponent') searchInputComponent: SearchInputComponent;
@ViewChild('editModal') editModal: AlertModal;
@ViewChild('deleteModal') deleteModal: AlertModal;
private selectedMenuItems: string[] = [];
public checkboxes: CheckMenuItem[] = [];
public menuItems: MenuItem[] = [];
// public rootMenuForm: FormGroup;
public menuItemForm: FormGroup;
public keyword = '';
public communities: Portal[] = [];
public portal: string;
public properties: EnvProperties = properties;
public showLoading = true;
public isPortalAdministrator = null;
public filterForm: FormGroup;
public typeOptions = [
{label: 'Internal Link', value: 'internal'},
{label: 'External Link', value: 'external'}
]
public selectedKeyword: string;
private subscriptions: any[] = [];
constructor(private element: ElementRef, private route: ActivatedRoute,
private _router: Router, private title: Title,
private _helpContentService: HelpContentService,
private userManagementService: UserManagementService, private _fb: FormBuilder) {
}
ngOnInit() {
this.filterForm = this._fb.group({
keyword: [''],
status: ['resources', Validators.required]
});
this.userManagementService.getUserInfo().subscribe(user => {
this.portal = (this.route.snapshot.data.portal) ? this.route.snapshot.data.portal : this.route.snapshot.params[this.route.snapshot.data.param];
if (this.route.snapshot.data.portal) {
this.title.setTitle(StringUtils.capitalize(this.portal) + ' | Menu');
} else if (this.route.snapshot.params[this.route.snapshot.data.param]) {
this.title.setTitle(this.portal.toUpperCase() + ' | Menu');
} else {
this.title.setTitle('Administrator Dashboard | Menu');
}
this.isPortalAdministrator = Session.isPortalAdministrator(user) && !this.portal;
});
this.showLoading = false;
}
ngOnDestroy(): void {
this.subscriptions.forEach(value => {
if (value instanceof Subscriber) {
value.unsubscribe();
} else if (value instanceof Function) {
value();
}
});
}
// public newRootMenu() {
// this.rootMenuForm = this._fb.group({
// id: this._fb.control(null),
// title: this._fb.control("",Validators.required),
// route: this._fb.control(""),
// isEnabled: this._fb.control("",Validators.required),
// });
// this.menuItemsModalOpen('Create Root Menu', 'Save Changes');
// }
public getSelectedMenuItems(): string[] {
return this.checkboxes.filter(menuItem => menuItem.checked == true).map(checkedMenuItem => checkedMenuItem.menuItem).map(res => res.id);
}
public confirmDeleteSelectedMenuItems() {
this.selectedMenuItems = this.getSelectedMenuItems();
this.confirmModalOpen();
}
private confirmModalOpen() {
this.deleteModal.cancelButton = true;
this.deleteModal.okButton = true;
this.deleteModal.alertTitle = 'Delete Confirmation';
this.deleteModal.message = 'Are you sure you want to delete the selected menu item(s)?';
this.deleteModal.okButtonText = 'Yes';
this.deleteModal.open();
}
public newMenuItem() {
this.menuItemForm = this._fb.group({
id: this._fb.control(""),
title: this._fb.control("",Validators.required),
type: this._fb.control("",Validators.required),
route: this._fb.control(""),
url: this._fb.control(""),
isEnabled: this._fb.control("",Validators.required),
});
this.menuItemsModalOpen('Create Menu Item', 'Save Changes');
}
public editMenuItem() {
this.menuItemForm = this._fb.group({
id: this._fb.control("id"),
title: this._fb.control("HardcodedName",Validators.required),
type: this._fb.control("internal",Validators.required),
route: this._fb.control("routeAlex"),
url: this._fb.control("urlAlex"),
isEnabled: this._fb.control("enabled",Validators.required),
});
this.menuItemsModalOpen('Edit Menu Item', 'Save Changes');
}
public deleteMenuItem() {
console.log('Delete menu item');
}
private menuItemsModalOpen(title: string, yesBtn: string) {
this.editModal.cancelButton = true;
this.editModal.okButton = true;
this.editModal.okButtonLeft = false;
this.editModal.alertTitle = title;
this.editModal.okButtonText = yesBtn;
this.editModal.open();
}
public toggleMenuItems(status: boolean, ids: string[]) {
}
public onSearchClose() {
this.selectedKeyword = this.filterForm.value;
}
public reset() {
this.selectedKeyword = null;
this.searchInputComponent.reset();
}
selectAll() {
let checked = this.getSelectedMenuItems().length != this.checkboxes.length;
for (let check of this.checkboxes) {
check.checked = checked;
}
}
}

View File

@ -0,0 +1,31 @@
import {NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
import {CommonModule} from '@angular/common';
import {MenuComponent} from './menu.component';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {AlertModalModule} from '../../utils/modal/alertModal.module';
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {AdminToolServiceModule} from "../../services/adminToolService.module";
import {InputModule} from "../../sharedComponents/input/input.module";
import {PageContentModule} from "../sharedComponents/page-content/page-content.module";
import {AdminTabsModule} from "../sharedComponents/admin-tabs/admin-tabs.module";
import {MenuRoutingModule} from "./menu-routing.module";
import {SearchInputModule} from "../../sharedComponents/search-input/search-input.module";
import {IconsModule} from "../../utils/icons/icons.module";
import {IconsService} from "../../utils/icons/icons.service";
import {add} from "../../utils/icons/icons";
import {LoadingModule} from "../../utils/loading/loading.module";
@NgModule({
imports: [
CommonModule, RouterModule, FormsModule, AdminToolServiceModule,
AlertModalModule, ReactiveFormsModule, MatSlideToggleModule, InputModule, PageContentModule, AdminTabsModule, MenuRoutingModule, SearchInputModule, IconsModule, LoadingModule
],
declarations: [MenuComponent],
exports: [MenuComponent]
})
export class MenuModule {
constructor(private iconsService: IconsService) {
this.iconsService.registerIcons([add]);
}
}

View File

@ -3,7 +3,7 @@ import {Session, User} from "../../../login/utils/helper.class";
import {UserManagementService} from "../../../services/user-management.service";
import {Subscriber} from "rxjs";
import {ActivatedRoute} from "@angular/router";
import {HelperFunctions} from "../../../utils/HelperFunctions.class";
import { properties } from 'src/environments/environment';
@Component({
selector: 'admin-tabs',
@ -12,6 +12,7 @@ import {HelperFunctions} from "../../../utils/HelperFunctions.class";
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'portal'"><a routerLink="../portals"><span class="title">Portals</span></a></li>
<li [class.uk-active]="tab === 'page'"><a routerLink="../pages"><span class="title">Pages</span></a></li>
<li [class.uk-active]="tab === 'entity'"><a routerLink="../entities"><span class="title">Entities</span></a></li>
<li *ngIf="env == 'development'" [class.uk-active]="tab === 'menu'"><a routerLink="../menu"><span class="title">Menu</span></a></li>
<li *ngIf="isPortalAdmin && !portal" [class.uk-active]="tab === 'class'"><a routerLink="../classes"><span class="title">Classes</span></a></li>
</ul>
`
@ -25,7 +26,9 @@ export class AdminTabsComponent implements OnInit {
@Input()
public user: User;
@Input()
public tab: "portal"| "page" | "entity" | "class" = 'page';
public tab: "portal" | "page" | "entity" | "menu" | "class" = 'page';
public env = properties.environment;
private subscriptions: any[] = [];
constructor(private route: ActivatedRoute, private userManagementService: UserManagementService) {

View File

@ -58,104 +58,6 @@ import {HelperFunctions} from "../../utils/HelperFunctions.class";
</div>
</div>
</ng-container>
<!-- <ng-container *ngIf="connectLinksView; else elseBlock"> -->
<!-- One gateway link -->
<!-- <div *ngIf="gateways && gateways.length === 1" class="uk-margin-medium-top uk-width-1-2@m">
<div class="uk-card uk-card-default uk-flex">
<div class="uk-width-2-3@m uk-card-body flex-column">
<img *ngIf="gateways[0].logo" src="{{gateways[0].logo}}" alt="OpenAIRE Gateway logo" class="gateway-link-logo">
<div>
<span class="uk-text-muted">Visit: </span>
<a href="{{gateways[0].link}}" target="_blank">
{{gateways[0].labelContext}}
<span class="custom-external custom-icon space"></span>
</a>
</div>
</div>
<div class="uk-width-1-3@m uk-position-relative">
<img class="uk-position-bottom-right" src="assets/common-assets/connect_image_faded.png" alt="OpenAIRE Connect image">
</div>
</div>
</div> -->
<!-- Two gateway links -->
<!-- <div *ngIf="gateways && gateways.length === 2" class="uk-margin-large-top uk-margin-large-right">
<div class="uk-card uk-card-default uk-flex">
<div class="uk-width-2-3@m uk-card-body uk-flex flex-gap">
<div class="flex-column min-width-30">
<img *ngIf="gateways[0].logo" src="{{gateways[0].logo}}" alt="sOpenAIRE Gateway logo" class="gateway-link-logo">
<div>
<span class="uk-text-muted">Visit: </span>
<a href="{{gateways[0].link}}" target="_blank">
{{gateways[0].labelContext}}
<span class="custom-external custom-icon space"></span>
</a>
</div>
</div>
<div class="verticalLine"></div>
<div class="flex-column min-width-30">
<img *ngIf="gateways[1].logo" src="{{gateways[1].logo}}" alt="OpenAIRE Gateway logo" class="gateway-link-logo">
<div>
<span class="uk-text-muted">Visit: </span>
<a href="{{gateways[1].link}}" target="_blank">
{{gateways[1].labelContext}}
<span class="custom-external custom-icon space"></span>
</a>
</div>
</div>
</div>
<div class="uk-width-1-3@m uk-position-relative">
<img class="uk-position-bottom-right custom-height-130" src="assets/common-assets/connect_image_faded.png" alt="OpenAIRE Connect image">
</div>
</div>
</div> -->
<!-- Three or more gateway links -->
<!-- <div *ngIf="gateways && gateways.length > 2" class="uk-margin-large-top uk-margin-large-right">
<div class="uk-card uk-card-default uk-flex">
<div class="uk-width-expand@m uk-card-body uk-padding-remove-right uk-flex flex-gap">
<div class="list">
<div>
<span class="uk-text-muted">Visit Connect gateways: </span>
</div>
<ul class="custom-list">
<li *ngFor="let gateway of gateways">
<a href="{{gateway.link}}" target="_blank">
{{ gateway.labelContext }}
<span class="custom-external custom-icon space"></span>
</a>
</li>
</ul>
</div>
</div>
<div class="uk-width-small@m uk-position-relative">
<img class="uk-position-bottom-right custom-height-130" src="assets/common-assets/connect_image_faded.png" alt="OpenAIRE Connect image">
</div>
</div>
</div> -->
<!-- </ng-container> -->
<!-- <ng-template #elseBlock>
<div class="uk-text-muted">Communities</div>
<div class="uk-margin-small-left" *ngFor="let item of contexts.slice(0, showNum); let i=index">
<span>
<span>{{item['labelContext']}}</span> -->
<!-- <a *ngIf="item['link']; else noLink" [href]="item['link']" target="_blank">{{item['labelContext']}}</a> -->
<!-- <ng-template #noLink> -->
<!-- </ng-template> -->
<!-- <span *ngIf="item['labelCategory']"><span
uk-icon="icon: arrow-right"></span>{{item['labelCategory']}}</span>
<span *ngIf="item['labelConcept']">: {{item['labelConcept']}}</span>
</span>
</div>
<div *ngIf="showNum > threshold" class="uk-text-right">
<a (click)="showNum = threshold; scroll()">
View less
</a>
</div>
<div *ngIf="showNum == threshold && contexts && contexts.length > threshold" class="uk-text-right">
<a (click)="showNum = contexts.length;">
View more
</a>
</div>
</ng-template> -->
`
})
@ -182,16 +84,13 @@ export class RelatedToComponent implements OnInit {
this.userManagementService.getUserInfo().subscribe( user => {
//- handling subscribe errors?
this.subscriptions.push(
this.communityService.getCommunity(context.idContext).subscribe( community => {
this.communityService.getCommunityInfo(context.idContext).subscribe( community => {
if(community && !ConnectHelper.isPrivate(community,user) && (this.currentCommunity != context.idContext)) {
// creating the link, based on the enviroment
let url = '';
if(properties.environment == "beta") {
url = 'https://beta.' + context.idContext + '.openaire.eu';
context.link = 'https://beta.' + context.idContext + '.openaire.eu';
} else {
url = 'https://' + context.idContext + '.openaire.eu';
context.link = 'https://' + context.idContext + '.openaire.eu';
}
context.link = url;
for(let gateway of this.gateways) {
if(gateway.link == context.link) {
return; // skips so that we don't get duplicate gateways

View File

@ -82,3 +82,8 @@ export class SideMenuItem {
items: RootMenuItem[] = [];
ukIcon: string = '';
}
export interface CheckMenuItem {
menuItem: MenuItem;
checked: boolean;
}

View File

@ -7,7 +7,9 @@ import {ErrorCodes} from "../../properties/errorCodes";
template: `
<errorMessages *ngIf="resultType" [status]="[fetch.searchUtils.status]" [type]="getEntityName(resultType, true, true)"
tab_error_class=true></errorMessages>
<a *ngIf="fetch.searchUtils.status == errorCodes.LOADING" class="uk-invisible"
[queryParams]="params" [routerLink]="searchLinkToAdvancedPage"></a>
<div *ngIf="fetch.searchUtils.status == errorCodes.DONE">
<div class="tab-header">
<span *ngIf="!customTitle && resultType"><span *ngIf="resultType != 'organization' && resultType != 'dataprovider' && resultType != 'project'">Recent</span>