diff --git a/package.json b/package.json index 6008bee..982503c 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "jquery": "^3.2.1", "ng2-ckeditor": "1.1.9", "ngx-bootstrap": "^1.6.6", + "ngx-color-picker": "^4.5.3", "ngx-json-ld": "0.1.6", "rxjs": "^5.4.2", "ts-md5": "^1.2.0", diff --git a/src/app/app.component.html b/src/app/app.component.html index 39eec6e..a27d03c 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -30,6 +30,12 @@ Community profile +
  • + + + Community Layout + +
  • diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts index 3ca3456..14d1b13 100644 --- a/src/app/app.routing.ts +++ b/src/app/app.routing.ts @@ -38,6 +38,11 @@ const appRoutes: Routes = [ loadChildren: './pages/community/community-edit-form/community-edit-form.module#CommunityEditFormModule', resolve: { envSpecific: EnvironmentSpecificResolver } }, + { + path: 'community-layout', + loadChildren: './pages/community/layout/community-layout.module#CommunityLayoutModule', + resolve: { envSpecific: EnvironmentSpecificResolver } + }, { path: 'manage-zenodo-communities', loadChildren: './pages/zenodo-communities/zenodo-communities.module#ZenodoCommunitiesModule', diff --git a/src/app/pages/community/layout/community-layout-routing.module.ts b/src/app/pages/community/layout/community-layout-routing.module.ts new file mode 100644 index 0000000..f3fc3c7 --- /dev/null +++ b/src/app/pages/community/layout/community-layout-routing.module.ts @@ -0,0 +1,14 @@ +import { NgModule } from '@angular/core'; +import {RouterModule} from '@angular/router'; +import {CommunityLayoutComponent} from './community-layout.component'; +import {IsCommunity} from '../../../openaireLibrary/connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../../openaireLibrary/connect/communityGuard/connectAdminLoginGuard.guard'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', canActivate: [IsCommunity, ConnectAdminLoginGuard], component: CommunityLayoutComponent} + ]) + ] +}) +export class CommunityLayoutRoutingModule { } diff --git a/src/app/pages/community/layout/community-layout.component.html b/src/app/pages/community/layout/community-layout.component.html new file mode 100644 index 0000000..335d678 --- /dev/null +++ b/src/app/pages/community/layout/community-layout.component.html @@ -0,0 +1,39 @@ +
    +
    Edit community layout
    +
    + + + + + + + + + +
    Color: + + Change your community color
    + + + + + + + + + + + +
    +
    + + + + +
    +
    +
    +
    diff --git a/src/app/pages/community/layout/community-layout.component.ts b/src/app/pages/community/layout/community-layout.component.ts new file mode 100644 index 0000000..c3efe85 --- /dev/null +++ b/src/app/pages/community/layout/community-layout.component.ts @@ -0,0 +1,134 @@ +import {Component, OnInit, ElementRef} from '@angular/core'; +import {ActivatedRoute} from '@angular/router'; + + +import {EnvProperties} from '../../../openaireLibrary/utils/properties/env-properties'; +import {LayoutService} from '../../../openaireLibrary/services/layout.service'; + +@Component({ + selector: 'community-layout', + templateUrl: './community-layout.component.html', +}) + +export class CommunityLayoutComponent implements OnInit { + + public showLoading = true; + public errorMessage = ''; + + public successfulSaveMessage = ''; + public successfulResetMessage = ''; + + public hasChanged = false; + public communityId = null; + public layout = null; + public properties: EnvProperties = null; + + constructor (private element: ElementRef, + private route: ActivatedRoute, + private _layoutService: LayoutService) { } + + + ngOnInit() { + this.route.data.subscribe((data: { envSpecific: EnvProperties }) => { + this.properties = data.envSpecific; + this.route.queryParams.subscribe( + communityId => { + this.scroll(); + this.communityId = communityId['communityId']; + if (this.communityId != null && this.communityId !== '') { + this.showLoading = true; + this.errorMessage = ''; + this._layoutService.getLayout(this.communityId, + this.properties.adminToolsAPIURL).subscribe ( + layout => { + this.layout = layout; + this.showLoading = false; + }, + error => this.handleError('System error retrieving community layout', error) + ); + } + }); + }); + } + + public scroll() { + if (typeof document !== 'undefined') { + this.element.nativeElement.scrollIntoView(); + } + } + + public updateLayout() { + if (this.communityId != null && this.communityId !== '') { + this.showLoading = true; + this._layoutService.saveLayout(this.communityId, + this.properties.adminToolsAPIURL, this.layout).subscribe ( + layout => { + this.layout = layout; + this.showLoading = false; + this.handleSuccessfulSave('Community Layout saved!'); + }, + error => this.handleError('System error saving community layout', error) + ); + this.resetChange(); + } + } + + public resetLayout() { + if (this.communityId != null && this.communityId !== '') { + this.showLoading = true; + this._layoutService.getLayout(this.communityId, + this.properties.adminToolsAPIURL).subscribe ( + layout => { + this.layout = layout; + this.showLoading = false; + this.handleSuccessfulReset('Community Layout reset!'); + }, + error => this.handleError('System error retrieving community layout', error) + ); + this.resetChange(); + } + } + + public loadDefaultLayout() { + if (this.communityId != null && this.communityId !== '') { + this.showLoading = true; + this._layoutService.loadDefaultLayout(this.communityId, + this.properties.adminToolsAPIURL).subscribe ( + layout => { + this.layout = layout; + this.showLoading = false; + this.handleSuccessfulReset('Default Community Layout has been loaded!'); + }, + error => this.handleError('System error loading default community layout', error) + ); + this.resetChange(); + } + } + + private change() { + this.hasChanged = true; + this.successfulSaveMessage = ''; + this.successfulResetMessage = ''; + } + + private resetChange() { + this.hasChanged = false; + } + + handleError(message: string, error) { + this.errorMessage = message; + console.log('Server responded: ' + error); + + this.showLoading = false; + } + + handleSuccessfulSave(message) { + this.showLoading = false; + this.successfulSaveMessage = message; + } + + handleSuccessfulReset(message) { + this.showLoading = false; + this.successfulResetMessage = message; + } +} diff --git a/src/app/pages/community/layout/community-layout.module.ts b/src/app/pages/community/layout/community-layout.module.ts new file mode 100644 index 0000000..a2a26e5 --- /dev/null +++ b/src/app/pages/community/layout/community-layout.module.ts @@ -0,0 +1,28 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {RouterModule} from '@angular/router'; + +import {CommunityLayoutComponent} from './community-layout.component'; + +import {CommunityLayoutRoutingModule} from './community-layout-routing.module'; +import {IsCommunity} from '../../../openaireLibrary/connect/communityGuard/isCommunity.guard'; +import {ConnectAdminLoginGuard} from '../../../openaireLibrary/connect/communityGuard/connectAdminLoginGuard.guard'; +import {ColorPickerModule} from 'ngx-color-picker'; +import {LayoutService} from '../../../openaireLibrary/services/layout.service'; + +@NgModule({ + imports: [ + CommunityLayoutRoutingModule, CommonModule, RouterModule, ColorPickerModule + ], + declarations: [ + CommunityLayoutComponent + ], + providers: [ + IsCommunity, ConnectAdminLoginGuard, LayoutService + ], + exports: [ + CommunityLayoutComponent + ] +}) + +export class CommunityLayoutModule { } diff --git a/src/app/services/help-content.service.ts b/src/app/services/help-content.service.ts index 5e18af7..d0b3483 100644 --- a/src/app/services/help-content.service.ts +++ b/src/app/services/help-content.service.ts @@ -10,7 +10,6 @@ import { Community } from "../domain/community"; import { Entity } from "../domain/entity"; import { DivId } from "../domain/divId"; import { DivHelpContent } from "../domain/div-help-content"; -import {COOKIE} from "../openaireLibrary/login/utils/helper.class" import {StatisticsDisplay, StatisticsSummary} from '../openaireLibrary/connect/statistics/statisticsEntities'; import { CustomOptions } from '../openaireLibrary/services/servicesUtils/customOptions.class'; diff --git a/src/assets/env-properties.json b/src/assets/env-properties.json index 03cf7ce..53b4bcf 100644 --- a/src/assets/env-properties.json +++ b/src/assets/env-properties.json @@ -49,7 +49,7 @@ "cacheUrl" :"http://scoobydoo.di.uoa.gr:3000/get?url=", - "adminToolsAPIURL" :"http://duffy.di.uoa.gr:8080/uoa-admin-tools/", + "adminToolsAPIURL" :"http://mpagasas.di.uoa.gr:8080/uoa-admin-tools/", "adminToolsCommunity" :"openaire", "communityAPI": "https://dev-openaire.d4science.org/openaire/community/",