Revision 58098
Added by Stefania Martziou about 4 years ago
sidemenu.component.ts | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Created by stefania on 7/5/16. |
3 | 3 |
*/ |
4 |
import { Component, DoCheck, OnInit, ViewEncapsulation} from '@angular/core';
|
|
4 |
import { Component, OnInit } from '@angular/core';
|
|
5 | 5 |
import { AuthenticationService } from '../../services/authentication.service'; |
6 | 6 |
import { environment } from '../../../environments/environment'; |
7 |
import {FormGroup} from "@angular/forms";
|
|
8 |
import {RepositorySnippet} from '../../domain/typeScriptClasses';
|
|
9 |
import {loadingReposMessage, loadingUserRepoInfoEmpty, reposRetrievalError} from '../../domain/shared-messages';
|
|
10 |
import {RepositoryService} from '../../services/repository.service';
|
|
7 |
import {Repository, RepositorySnippet} from '../../domain/typeScriptClasses';
|
|
8 |
import { RepositoryService } from '../../services/repository.service';
|
|
9 |
import { ActivatedRoute, Router } from "@angular/router";
|
|
10 |
import { SharedService } from "../../services/shared.service";
|
|
11 | 11 |
|
12 | 12 |
@Component({ |
13 | 13 |
selector: 'side-menu', |
14 | 14 |
templateUrl: './sidemenu.component.html', |
15 |
// styleUrls: ['./sidemenu.component.css'], |
|
16 |
encapsulation: ViewEncapsulation.None |
|
17 | 15 |
}) |
18 | 16 |
|
19 | 17 |
export class SideMenuComponent implements OnInit { |
... | ... | |
28 | 26 |
|
29 | 27 |
userEmail: string; |
30 | 28 |
reposOfUser: RepositorySnippet[] = []; |
31 |
skipGridView = false; |
|
29 |
visibleReposOfUser: RepositorySnippet[] = []; |
|
30 |
allReposVisible: boolean = false; |
|
32 | 31 |
|
33 | 32 |
constructor(public authService: AuthenticationService, |
34 |
private repositoryService: RepositoryService) { } |
|
33 |
private repositoryService: RepositoryService, |
|
34 |
private route: ActivatedRoute, |
|
35 |
private router: Router, |
|
36 |
private sharedService: SharedService) { } |
|
35 | 37 |
|
36 | 38 |
ngOnInit() { |
37 | 39 |
|
... | ... | |
53 | 55 |
const baseUrl = window.location.origin; |
54 | 56 |
this.inBeta = ( baseUrl.includes('beta') || baseUrl.includes('athenarc') ); |
55 | 57 |
|
56 |
this.getReposOfUser(); |
|
58 |
if(this.sharedService.getRepositoriesOfUser() && this.sharedService.getRepositoriesOfUser().length>0) { |
|
59 |
this.reposOfUser = this.sharedService.getRepositoriesOfUser(); |
|
60 |
this.initSideMenuRepos(); |
|
61 |
} else { |
|
62 |
this.getReposOfUser(); |
|
63 |
} |
|
64 |
|
|
65 |
this.sharedService.repositoriesOfUser$.subscribe( |
|
66 |
r => { |
|
67 |
this.reposOfUser = r; |
|
68 |
this.initSideMenuRepos(); |
|
69 |
} |
|
70 |
); |
|
71 |
|
|
72 |
// this.getReposOfUser(); |
|
57 | 73 |
} |
58 | 74 |
|
59 | 75 |
onClick(id: string) { |
... | ... | |
102 | 118 |
getReposOfUser(): void { |
103 | 119 |
this.repositoryService.getRepositoriesOfUser() |
104 | 120 |
.subscribe( |
105 |
repos => { this.reposOfUser = repos; }, |
|
106 |
error => { console.log(error); }, |
|
107 |
() => { if (this.reposOfUser.length == 1) { this.skipGridView = true; } } |
|
121 |
repos => { |
|
122 |
this.reposOfUser = repos; |
|
123 |
// this.sharedService.setRepositoriesOfUser(repos); |
|
124 |
this.initSideMenuRepos(); |
|
125 |
}, |
|
126 |
error => { console.log(error); } |
|
108 | 127 |
); |
109 | 128 |
} |
129 |
|
|
130 |
initSideMenuRepos() { |
|
131 |
|
|
132 |
let index: number = 0; |
|
133 |
|
|
134 |
if(this.reposOfUser.length>5) { |
|
135 |
for(let _i = 0; _i < 5; _i++) { |
|
136 |
this.visibleReposOfUser.push(this.reposOfUser[_i]); |
|
137 |
} |
|
138 |
} else { |
|
139 |
this.visibleReposOfUser = Object.assign([], this.reposOfUser); |
|
140 |
} |
|
141 |
|
|
142 |
let route = this.router.url; |
|
143 |
let repositoryID = ''; |
|
144 |
if(route.includes('repository') || route.includes('repositoryAdmin')) { |
|
145 |
let repositoryIndex = route.indexOf('repository'); |
|
146 |
repositoryID = route.substr(repositoryIndex).split('/')[1]; |
|
147 |
|
|
148 |
if(!route.includes('repositoryAdmin')) { |
|
149 |
index = this.reposOfUser.findIndex(x => x.id === repositoryID); |
|
150 |
if(index>5) |
|
151 |
this.showMoreRepos(); |
|
152 |
} |
|
153 |
|
|
154 |
if(route.includes('repositoryAdmin')) { |
|
155 |
|
|
156 |
} |
|
157 |
} |
|
158 |
} |
|
159 |
|
|
160 |
showMoreRepos() { |
|
161 |
this.visibleReposOfUser = Object.assign([], this.reposOfUser); |
|
162 |
this.allReposVisible = true; |
|
163 |
} |
|
164 |
|
|
165 |
showLessRepos() { |
|
166 |
this.visibleReposOfUser = []; |
|
167 |
for(let _i = 0; _i < 5; _i++) { |
|
168 |
this.visibleReposOfUser.push(this.reposOfUser[_i]); |
|
169 |
} |
|
170 |
this.allReposVisible = false; |
|
171 |
} |
|
110 | 172 |
} |
Also available in: Unified diff
Second commit for the new layout provided by the UX team