Skip to content

Commit 796afb5

Browse files
authored
Issue + Candidate fixes (#160)
* addded nullcheck for issue priv check * fixed issue routing after create * removed forced redirect that breaks routing * fixed routing by url * removed issue scroll bar if list is empty * removed tracing * added fallback action for issue * fixed console errors for pattern details * added nullcheck * removed store from candidate management * removed unused imports * updated typescript and fixed pr comments * changed confirmdialog and route subscription unsubscribe
1 parent cc9b1ad commit 796afb5

File tree

17 files changed

+1694
-1858
lines changed

17 files changed

+1694
-1858
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"stylelint": "^13.5.0",
7979
"stylelint-config-sass-guidelines": "^7.0.0",
8080
"ts-node": "~8.0.1",
81-
"typescript": "~3.6.4"
81+
"typescript": "~3.7.7"
8282
},
8383
"browser": {
8484
"fs": false

src/app/app-routing.module.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import { ToasterModule } from 'angular2-toaster';
55
import { PageNotFoundComponent } from './core/component/page-not-found/page-not-found.component';
66
import { AuthGuardService as AuthGuard } from './authentication/_services/auth-guard.service';
77
import { PatternLanguageManagementResolverService } from './pattern-language-management/pattern-language-management/pattern-language-management-resolver.service'; // eslint-disable-line max-len
8-
import { UserRole } from './core/user-management';
9-
import { PrintHook } from '@angular/flex-layout';
108
import { Privilege } from './core/user-management/_models/privilege.enum';
119
import { globals } from './globals';
1210
/*
@@ -45,11 +43,11 @@ const routes: Routes = [
4543
loadChildren: () => import('./design-model-module/design-model.module').then(m => m.DesignModelModule),
4644
},
4745
{
48-
path: 'candidate',
46+
path: globals.pathConstants.candidate,
4947
loadChildren: () => import('./candidate-management/candidate-management.module').then(m => m.CandidateManagementModule),
5048
},
5149
{
52-
path: 'issue',
50+
path: globals.pathConstants.issue,
5351
loadChildren: () => import('./issue-management/issue-management.module').then(m => m.IssueManagementModule),
5452
},
5553
{
@@ -68,10 +66,7 @@ const routes: Routes = [
6866
path: 'oauth-callback',
6967
component: ProcessOauthCallbackComponent
7068
},
71-
{
72-
path: '**',
73-
component: PageNotFoundComponent
74-
},
69+
{ path: '**', component: PageNotFoundComponent }
7570
];
7671

7772
@NgModule({

src/app/authentication/_services/authentication.service.ts

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export class AuthenticationService {
5252
} else if (token && !this.jwtHelper.isTokenExpired(token)) {
5353
this.getUserInfo();
5454
this.getRoles();
55-
this.router.navigate(['/']);
5655

5756
} else if (token && this.getRefreshToken() && this.jwtHelper.isTokenExpired(this.getAccessToken())) {
5857
this.refreshToken();

src/app/candidate-management/candidate-management-detail/candidate-management-detail.component.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</pp-author-picker>
1717

1818
<pp-pattern-language-picker class="detail-component" [disabled]="disabled"
19-
[patternLanguageSelected]="candidate.patternLanguageId" [confirmDialog]="confirmDialog"
19+
[patternLanguageSelected]="candidate.patternLanguageId" [confirmDialog]="confirmDialogData"
2020
(patternLanguageSelectedChange)="patternLanguageSelectedChange($event)"></pp-pattern-language-picker>
2121

2222
<!-- <pp-rating class="detail-component" [disabled]="!candidate.id" [upVotes]="candidate.upVotes" -->
@@ -59,13 +59,13 @@
5959
<button mat-flat-button type="button" color="warn" (click)="cancelPattern()">Cancel</button>
6060
</div>
6161
</mat-card>
62-
<pp-evidence-list [evidences]="candidate.evidences" [disabled]="!candidate.id"
62+
<pp-evidence-list [evidences]="candidate?.evidences" [disabled]="candidate?.id == null"
6363
(createEvidenceEvent)="createEvidence($event)" (updateEvidenceEvent)="updateEvidence($event)"
6464
(deleteEvidenceEvent)="deleteEvidence($event)" (ratingEvent)="updateRatingEvidence($event)">
6565
</pp-evidence-list>
6666
</div>
6767
<pp-comment-list *ngIf="candidateHeight" class="right" [style.height.px]="candidateHeight"
68-
[data]="candidate.comments" [disabled]="!candidate.id" (createCommentEvent)="createComment($event)"
68+
[data]="candidate?.comments" [disabled]="candidate?.id == null" (createCommentEvent)="createComment($event)"
6969
(updateCommentEvent)="updateComment($event)" (deleteCommentEvent)="deleteComment($event)"
7070
(ratingEvent)="updateRatingComment($event)">
7171
</pp-comment-list>

src/app/candidate-management/candidate-management-detail/candidate-management-detail.component.ts

+59-42
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Component, OnInit, ViewChild, ElementRef, ChangeDetectorRef, AfterViewInit } from '@angular/core';
1+
import { Component, OnInit, ViewChild, ElementRef, ChangeDetectorRef, AfterViewInit, OnDestroy } from '@angular/core';
22
import { Router, ActivatedRoute } from '@angular/router';
33
import { TdTextEditorComponent } from '@covalent/text-editor';
4-
import { Candidate, CandidateManagementService, CandidateManagementStore } from 'src/app/core/candidate-management';
4+
import { Candidate, CandidateManagementService } from 'src/app/core/candidate-management';
55
import PatternLanguageSchemaModel from 'src/app/core/model/pattern-language-schema.model';
66
import PatternSectionSchema from 'src/app/core/model/hal/pattern-section-schema.model';
77
import { patternLanguageNone } from 'src/app/core/component/pattern-language-picker/pattern-language-picker.component';
@@ -18,13 +18,14 @@ import { PrivilegeService } from 'src/app/authentication/_services/privilege.ser
1818
import { Author, AuthorModel } from 'src/app/core/author-management';
1919
import { environment } from 'src/environments/environment';
2020
import { AuthenticationService } from 'src/app/authentication/_services/authentication.service';
21+
import { Subscription } from 'rxjs';
2122

2223
@Component({
2324
selector: 'pp-candidate-management-detail',
2425
templateUrl: './candidate-management-detail.component.html',
2526
styleUrls: ['./candidate-management-detail.component.scss']
2627
})
27-
export class CandidateManagementDetailComponent implements OnInit, AfterViewInit {
28+
export class CandidateManagementDetailComponent implements OnInit, AfterViewInit, OnDestroy {
2829

2930
@ViewChild('textEditor') private _textEditor: TdTextEditorComponent;
3031
@ViewChild('candidateView') candidateDiv: ElementRef;
@@ -45,13 +46,14 @@ export class CandidateManagementDetailComponent implements OnInit, AfterViewInit
4546
pattern = false;
4647
treshhold = true;
4748
treshholdSetting = 4.0;
48-
confirmDialog: ConfirmData;
49+
private _confirmDialogData: ConfirmData;
50+
51+
private activeRouteSubscription: Subscription | null = null;
4952

5053
constructor(
5154
private router: Router,
5255
private activeRoute: ActivatedRoute,
5356
private candidateManagementService: CandidateManagementService,
54-
public candidateStore: CandidateManagementStore,
5557
private patternService: PatternService,
5658
public dialog: MatDialog,
5759
private p: PrivilegeService,
@@ -60,47 +62,63 @@ export class CandidateManagementDetailComponent implements OnInit, AfterViewInit
6062
) { }
6163

6264
ngOnInit(): void {
63-
64-
this.candidateStore.candidate.subscribe((_candidate: Candidate) => {
65-
if (_candidate && this.router.url.includes('detail')) {
66-
this.disabled = true;
67-
this.candidate = _candidate;
68-
this.contentToMarkdown();
69-
this.checkTreshhold();
70-
71-
} else if (_candidate && this.router.url.includes('edit')) {
72-
this.candidate = _candidate;
73-
this.contentToMarkdown();
74-
this.edit();
75-
this.checkTreshhold();
76-
77-
} else if (!_candidate && window.history.state.data && window.history.state.data instanceof Candidate) {
78-
this.candidate = window.history.state.data as Candidate
79-
this.contentToMarkdown();
80-
this.edit();
81-
this.checkTreshhold();
82-
83-
} else {
84-
this.disabled = false;
85-
this.candidate = new Candidate(null, 'New Candidate', null, null);
86-
this.patternLanguageSelectedChange(patternLanguageNone);
87-
// Preset author
88-
this.auth.user.subscribe(_user => {
89-
if (_user && !this.candidate.authors) this.candidate.authors = [new AuthorModel(_user.id, Author.OWNER, _user.name)];
90-
})
91-
}
92-
this.confirmDialog = {
93-
title: `Change Pattern Language for Candidate ${this.candidate.name}`,
94-
text: 'If you change the language everything writen will be deleted and the'
95-
+ ' new pattern schema will be used'
65+
this.activeRouteSubscription = this.activeRoute.params.subscribe(params => {
66+
let candidateUri = `/candidates/${params.name}`;
67+
switch (params.action) {
68+
case 'detail': {
69+
this.disabled = true;
70+
this.candidateManagementService.getCandidateByUri(candidateUri).subscribe(result => {
71+
this.candidate = result;
72+
this.contentToMarkdown();
73+
this.checkTreshhold();
74+
});
75+
break;
76+
}
77+
case 'edit': {
78+
this.candidateManagementService.getCandidateByUri(candidateUri).subscribe(result => {
79+
this.candidate = result;
80+
this.contentToMarkdown();
81+
this.edit();
82+
this.checkTreshhold();
83+
});
84+
break;
85+
}
86+
case 'create': {
87+
this.disabled = false;
88+
let candidateName = params.name ? params.name : 'New Candidate';
89+
this.candidate = new Candidate(null, candidateName, null, null);
90+
this.patternLanguageSelectedChange(patternLanguageNone);
91+
// Preset author
92+
this.auth.user.subscribe(_user => {
93+
if (_user && !this.candidate.authors) this.candidate.authors = [new AuthorModel(_user.id, Author.OWNER, _user.name)];
94+
});
95+
break;
96+
}
97+
default: {
98+
// Unknown action - show candidate list
99+
this.router.navigateByUrl('/candidate');
100+
break;
101+
}
96102
}
97103
});
98104
}
99105

106+
ngOnDestroy(): void {
107+
this.activeRouteSubscription?.unsubscribe();
108+
}
109+
100110
ngAfterViewInit(): void {
101111
this.setCommentSectionHeight();
102112
}
103113

114+
public get confirmDialogData() {
115+
return {
116+
title: `Change Pattern Language for Candidate ${this.candidate.name}`,
117+
text: 'If you change the language everything writen will be deleted and the'
118+
+ ' new pattern schema will be used'
119+
};
120+
}
121+
104122
// CHANGE MARKDOWN
105123
contentToMarkdown() {
106124
this.candidateMarkdown = `# ${this.candidate.name}\n`;
@@ -218,9 +236,6 @@ export class CandidateManagementDetailComponent implements OnInit, AfterViewInit
218236
})
219237

220238
this.candidateManagementService.createCandidate(this.candidate).subscribe(result => {
221-
this.candidate = result;
222-
this.contentToMarkdown();
223-
224239
// call update for all additional authors
225240
for(let author of authorlist) {
226241
if(author.userId !== first_author) {
@@ -230,7 +245,7 @@ export class CandidateManagementDetailComponent implements OnInit, AfterViewInit
230245
}
231246
}
232247

233-
this.disabled = true;
248+
this.router.navigate(['./candidate/detail', this.candidate.name]);
234249
})
235250
}
236251

@@ -239,6 +254,7 @@ export class CandidateManagementDetailComponent implements OnInit, AfterViewInit
239254
this.candidate = result;
240255
this.contentToMarkdown();
241256
this.disabled = true;
257+
this.router.navigate(['./candidate/detail', this.candidate.name]);
242258
})
243259
}
244260

@@ -390,4 +406,5 @@ export class CandidateManagementDetailComponent implements OnInit, AfterViewInit
390406
this.candidateHeight = this.candidateDiv.nativeElement.offsetHeight;
391407
this.ref.detectChanges();
392408
}
409+
393410
}

src/app/candidate-management/candidate-management.module.ts

+5-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { CoreModule } from '../core/core.module';
4-
import { RouterModule } from '@angular/router';
4+
import { RouterModule, Routes } from '@angular/router';
55
import { MatButtonModule } from '@angular/material/button';
66
import { MatSelectModule } from '@angular/material/select';
77
import { MatFormFieldModule } from '@angular/material/form-field';
@@ -15,7 +15,7 @@ import { MatToolbarModule } from '@angular/material/toolbar';
1515
import { MatExpansionModule } from '@angular/material/expansion';
1616
// Routing
1717

18-
export const CANDIATE_ROTUES = [
18+
export const CANDIDATE_ROUTES : Routes = [
1919
{
2020
path: '',
2121
children: [
@@ -24,32 +24,12 @@ export const CANDIATE_ROTUES = [
2424
component: CandidateManagementListComponent,
2525
},
2626
{
27-
path: 'detail/:name',
27+
path: ':action',
2828
component: CandidateManagementDetailComponent,
29-
// Will be used in the future
30-
// canActivate: [AuthGuard],
31-
// data: { role: UserRole.MEMBER }
3229
},
3330
{
34-
path: 'edit/:name',
31+
path: ':action/:name',
3532
component: CandidateManagementDetailComponent,
36-
// Will be used in the future
37-
// canActivate: [AuthGuard],
38-
// data: { role: UserRole.MEMBER }
39-
},
40-
{
41-
path: 'create',
42-
component: CandidateManagementDetailComponent,
43-
// Will be used in the future
44-
// canActivate: [AuthGuard],
45-
// data: { role: UserRole.MEMBER }
46-
},
47-
{
48-
path: 'create/:name',
49-
component: CandidateManagementDetailComponent,
50-
// Will be used in the future
51-
// canActivate: [AuthGuard],
52-
// data: { role: UserRole.MEMBER }
5333
}
5434
]
5535
}
@@ -63,7 +43,7 @@ export const CANDIATE_ROTUES = [
6343
imports: [
6444
CommonModule,
6545
CoreModule,
66-
RouterModule.forChild(CANDIATE_ROTUES),
46+
RouterModule.forChild(CANDIDATE_ROUTES),
6747
//Material
6848
MatButtonModule,
6949
MatSelectModule,

0 commit comments

Comments
 (0)