Skip to content

Commit

Permalink
Merge pull request #29 from dhlab-basel/wip/refactor
Browse files Browse the repository at this point in the history
Refactor: Clean up code and bug fixes
  • Loading branch information
kilchenmann authored Jun 20, 2019
2 parents 519c5af + 76bff6a commit a86f17f
Show file tree
Hide file tree
Showing 37 changed files with 517 additions and 73 deletions.
12 changes: 12 additions & 0 deletions .grenrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
"dataSource": "commits",
"prefix": "",
"includeMessages": "all",
"changelogFilename": "CHANGELOG.md",
"groupBy": {
"Enhancements:": ["feat"],
"Bug Fixes:": ["fix"],
"Documentation:": ["docs"],
"Other": ["chore", "refactor"]
}
};
8 changes: 4 additions & 4 deletions src/app/app-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class AppGlobal {
public static projectNav: MenuItem[] = [
{
label: 'Project information',
route: 'board',
route: 'info',
icon: 'assignment'
},
{
Expand All @@ -15,9 +15,9 @@ export class AppGlobal {
icon: 'group'
},
{
label: 'Groups',
route: 'groups',
icon: 'supervised_user_circle'
label: 'Permission groups',
route: 'permissions',
icon: 'lock_open'
},
{
label: 'Data model',
Expand Down
11 changes: 9 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { UsersComponent } from './system/users/users.component';
import { StatusComponent } from './system/status/status.component';
import { ResourceComponent } from './workspace/resource/resource.component';
import { CookiePolicyComponent } from './main/cookie-policy/cookie-policy.component';
import { GroupsComponent } from './system/groups/groups.component';
import { PermissionComponent } from './project/permission/permission.component';

const routes: Routes = [
{
Expand All @@ -49,17 +51,22 @@ const routes: Routes = [
{
path: '',
pathMatch: 'full',
redirectTo: 'board'
redirectTo: 'info'
},
{
path: 'board',
path: 'info',
component: BoardComponent
},
{
path: 'collaboration',
component: CollaborationComponent,
canActivate: [AuthGuard]
},
{
path: 'permissions',
component: PermissionComponent,
canActivate: [AuthGuard]
},
{
path: 'ontologies',
component: OntologyComponent,
Expand Down
11 changes: 9 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ import { GridComponent } from './main/grid/grid.component';
import { ResourceComponent } from './workspace/resource/resource.component';
import { CookiePolicyComponent } from './main/cookie-policy/cookie-policy.component';
import { InfoMenuComponent } from './main/info-menu/info-menu.component';
import { GroupsComponent } from './system/groups/groups.component';
import { GroupsListComponent } from './system/groups/groups-list/groups-list.component';
import { PermissionComponent } from './project/permission/permission.component';
import { AddGroupComponent } from './project/permission/add-group/add-group.component';

// translate: AoT requires an exported function for factories
export function HttpLoaderFactory(httpClient: HttpClient) {
Expand Down Expand Up @@ -113,7 +117,6 @@ export function initializeApp(appInitService: AppInitService) {
ResourceComponent,
ExpertSearchComponent,
AdvancedSearchComponent,

DashboardComponent,
DialogComponent,
SystemComponent,
Expand All @@ -123,7 +126,11 @@ export function initializeApp(appInitService: AppInitService) {
DialogHeaderComponent,
GridComponent,
CookiePolicyComponent,
InfoMenuComponent
InfoMenuComponent,
GroupsComponent,
GroupsListComponent,
PermissionComponent,
AddGroupComponent
],
imports: [
AppRoutingModule,
Expand Down
14 changes: 7 additions & 7 deletions src/app/main/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
<button mat-button routerLink="/" class="main-toolbar-button home-button">
<!-- <mat-icon svgIcon="kuirl_banner" class="large"></mat-icon> -->
<mat-icon svgIcon="kuirl_icon" class="small"></mat-icon>
<!-- {{appName}} -->
</button>
</span>
<span class="version mat-caption">
<!-- {{appVersion}} -->
</span>

<span class="fill-remaining-space"></span>

<span class="action">
<kui-fulltext-search [route]="'/search'" [projectfilter]="true"></kui-fulltext-search>
<kui-search-panel [route]="'/search'" [projectfilter]="true" [expert]="false" [advanced]="false">
</kui-search-panel>
<!-- <kui-fulltext-search [route]="'/search'" [projectfilter]="true"></kui-fulltext-search> -->
</span>
<button mat-icon-button [matMenuTriggerFor]="menu">
<button mat-button [matMenuTriggerFor]="menu">
<mat-icon>more_vert</mat-icon>
</button>
<mat-menu #menu="matMenu">
<button mat-menu-item routerLink="/search/advanced">
<span>Advanced</span>
<span>Advanced search</span>
</button>
<button mat-menu-item routerLink="/search/expert">
<span>Expert</span>
<span>Expert search</span>
</button>
</mat-menu>

Expand Down
4 changes: 2 additions & 2 deletions src/app/main/header/header.component.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.logo {
margin-left: -16px;
// margin-left: -16px;

.mat-icon {
height: 40px;
Expand All @@ -9,7 +9,7 @@
}

&.small {
margin-left: 12px;
// margin-left: 12px;
width: 40px;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/main/info-menu/info-menu.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<button mat-button [matMenuTriggerFor]="infoMenu" class="main-toolbar-button info-menu">
<mat-icon>network_check</mat-icon>
<mat-icon class="custom">network_check</mat-icon>
</button>

<mat-menu #infoMenu="matMenu" xPosition="before" class="menu">
Expand Down
3 changes: 2 additions & 1 deletion src/app/main/info-menu/info-menu.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatButtonModule, MatIconModule, MatListModule, MatMenuModule } from '@angular/material';
import { KuiCoreConfig, KuiCoreConfigToken } from '@knora/core';
import { KuiCoreConfig, KuiCoreConfigToken, KuiCoreModule } from '@knora/core';
import { InfoMenuComponent } from './info-menu.component';


Expand All @@ -14,6 +14,7 @@ describe('InfoMenuComponent', () => {
declarations: [InfoMenuComponent],
imports: [
HttpClientTestingModule,
KuiCoreModule,
MatButtonModule,
MatIconModule,
MatListModule,
Expand Down
16 changes: 11 additions & 5 deletions src/app/main/info-menu/info-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HttpClient, HttpResponse } from '@angular/common/http';
import { Component, Inject, OnInit } from '@angular/core';
import { MatIconRegistry } from '@angular/material';
import { DomSanitizer } from '@angular/platform-browser';
import { ApiService, KuiCoreConfig, KuiCoreConfigToken } from '@knora/core';
import { KuiCoreConfig, KuiCoreConfigToken } from '@knora/core';
import { MenuItem } from '../declarations/menu-item';

declare let require: any;
Expand All @@ -25,18 +25,18 @@ export class InfoMenuComponent implements OnInit {

versions: MenuItem[] = [
{
label: 'Kuirl v ' + this.appVersion,
label: '',
icon: 'kuirl_icon',
route: 'https://github.com/dhlab-basel/Kuirl/releases/tag/v' + this.appVersion
},
{
label: 'Knora v ',
label: 'Knora v',
icon: 'knora_icon',
route: 'https://github.com/dhlab-basel/Knora/releases/tag/v'
}
];

constructor (private _apiService: ApiService,
constructor (
@Inject(KuiCoreConfigToken) public config: KuiCoreConfig,
private _domSanitizer: DomSanitizer,
private _matIconRegistry: MatIconRegistry,
Expand All @@ -61,7 +61,9 @@ export class InfoMenuComponent implements OnInit {

ngOnInit() {

this._http.get<HttpResponse<any>>(this.config.api + '/v2/authentication', { observe: 'response' })
this.versions[0].label = this.config.name + ' v' + this.appVersion;

this._http.get<HttpResponse<any>>(this.config.api + '/admin/projects', { observe: 'response' })
.subscribe(
(resp: HttpResponse<any>) => {
// console.log('Stackoverflow', resp.headers.get('Server'));
Expand All @@ -80,6 +82,10 @@ export class InfoMenuComponent implements OnInit {

readVersion(v: string) {

if (!v) {
return;
}

const versions: string[] = v.split(' ');

this.apiVersion = versions[0].split('/')[1];
Expand Down
64 changes: 32 additions & 32 deletions src/app/project/collaboration/collaboration.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { ActivatedRoute, Params } from '@angular/router';
import { Session } from '@knora/authentication';
import { ApiServiceError, Project, ProjectsService, User } from '@knora/core';
import { CacheService } from '../../main/cache/cache.service';
import { AddUserComponent } from './add-user/add-user.component';
import { Session } from '@knora/authentication';

@Component({
selector: 'app-collaboration',
Expand Down Expand Up @@ -38,17 +38,17 @@ export class CollaborationComponent implements OnInit {

@ViewChild('addUserComponent') addUser: AddUserComponent;

constructor(private _cache: CacheService,
private _projectsService: ProjectsService,
private _route: ActivatedRoute,
private _titleService: Title) {
constructor (private _cache: CacheService,
private _projectsService: ProjectsService,
private _route: ActivatedRoute,
private _titleService: Title) {

// get the shortcode of the current project
this._route.parent.paramMap.subscribe((params: Params) => {
this.projectcode = params.get('shortcode');
});

// this.projectcode = this._route.parent.snapshot.params.shortcode;
// this.projectcode = this._route.parent.snapshot.params.shortcode;

// set the page title
this._titleService.setTitle('Project ' + this.projectcode + ' | Collaboration');
Expand Down Expand Up @@ -82,33 +82,33 @@ export class CollaborationComponent implements OnInit {

// get the project data from cache
this._cache
.get(
this.projectcode,
this._projectsService.getProjectByShortcode(
this.projectcode
)
.get(
this.projectcode,
this._projectsService.getProjectByShortcode(
this.projectcode
)
.subscribe(
(result: Project) => {
this.project = result;

// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin
? this.sysAdmin
: this.session.user.projectAdmin.some(e => e === this.project.id);

// get from cache: list of project members and groups
if (this.projectAdmin) {
this.refresh();
}

this.loading = false;
},
(error: ApiServiceError) => {
console.error(error);
this.loading = false;
)
.subscribe(
(result: Project) => {
this.project = result;

// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin
? this.sysAdmin
: this.session.user.projectAdmin.some(e => e === this.project.id);

// get from cache: list of project members and groups
if (this.projectAdmin) {
this.refresh();
}
);

this.loading = false;
},
(error: ApiServiceError) => {
console.error(error);
this.loading = false;
}
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<mat-form-field *ngIf="projectGroups.length > 0">
<mat-select placeholder="Group" [formControl]="groupCtrl" multiple (selectionChange)="onGroupSelect()"
<mat-select placeholder="Permission group" [formControl]="groupCtrl" multiple (selectionChange)="onGroupSelect()"
(openedChange)="onGroupChange()">
<mat-option *ngFor="let group of projectGroups" [value]="group.iri" [disabled]="disabled">
{{group.name}}</mat-option>
Expand Down
3 changes: 3 additions & 0 deletions src/app/project/permission/add-group/add-group.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>
add-group works!
</p>
Empty file.
25 changes: 25 additions & 0 deletions src/app/project/permission/add-group/add-group.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { AddGroupComponent } from './add-group.component';

describe('AddGroupComponent', () => {
let component: AddGroupComponent;
let fixture: ComponentFixture<AddGroupComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AddGroupComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AddGroupComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
22 changes: 22 additions & 0 deletions src/app/project/permission/add-group/add-group.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';

@Component({
selector: 'app-add-group',
templateUrl: './add-group.component.html',
styleUrls: ['./add-group.component.scss']
})
export class AddGroupComponent implements OnInit {

@Input() projectcode: string;

@Output() refreshParent: EventEmitter<any> = new EventEmitter<any>();

constructor () { }

ngOnInit() {
}

buildForm(): void {

}
}
Loading

0 comments on commit a86f17f

Please sign in to comment.