This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit 80b24ae1 authored by Michael Breu's avatar Michael Breu :speech_balloon:
Browse files

intermediate commit: fighting with dropdown

parent a9d127cc
No related merge requests found
...@@ -17,6 +17,7 @@ import { ActiveMenuDirective } from './layouts/navbar/active-menu.directive'; ...@@ -17,6 +17,7 @@ import { ActiveMenuDirective } from './layouts/navbar/active-menu.directive';
import { ErrorComponent } from './layouts/error/error.component'; import { ErrorComponent } from './layouts/error/error.component';
import { QueryParamModule } from '@ngqp/core'; import { QueryParamModule } from '@ngqp/core';
import { CacheService } from 'app/shared/service/cache.service'; import { CacheService } from 'app/shared/service/cache.service';
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';
@NgModule({ @NgModule({
imports: [ imports: [
...@@ -29,6 +30,7 @@ import { CacheService } from 'app/shared/service/cache.service'; ...@@ -29,6 +30,7 @@ import { CacheService } from 'app/shared/service/cache.service';
GitSearchV2EntityModule, GitSearchV2EntityModule,
GitSearchV2AppRoutingModule, GitSearchV2AppRoutingModule,
QueryParamModule, QueryParamModule,
NgbDropdown,
], ],
declarations: [MainComponent, NavbarComponent, ErrorComponent, PageRibbonComponent, ActiveMenuDirective, FooterComponent], declarations: [MainComponent, NavbarComponent, ErrorComponent, PageRibbonComponent, ActiveMenuDirective, FooterComponent],
bootstrap: [MainComponent], bootstrap: [MainComponent],
......
import { Injectable, OnDestroy, OnInit } from '@angular/core';
import { HttpResponse } from '@angular/common/http';
import { UserWatchListService } from 'app/entities/user-watch-list/user-watch-list.service';
import { IUserWatchList } from 'app/shared/model/user-watch-list.model';
import { AccountService } from 'app/core/auth/account.service';
import { Subscription } from 'rxjs';
import { Account } from 'app/core/user/account.model';
/**
provides infrastructure for watchlists management.
The manager is is charge to guarantee that the local watchlists and the watchlists on the server are in synchrony.
If the user is not logged in, the watchlists are undefined.
*/
@Injectable({ providedIn: 'root' })
export class WatchlistManager implements OnInit, OnDestroy {
account: Account | null = null;
authSubscription?: Subscription;
myWatchLists?: IUserWatchList[];
currentWatchlist? = '';
constructor(
protected watchListService: UserWatchListService,
private accountService: AccountService,
) {
this.authSubscription = this.accountService.getAuthenticationState().subscribe(account => {
this.account = account;
if(this.accountService.isAuthenticated()) {
this.watchListService.findMyWatchlists().subscribe((data: HttpResponse<IUserWatchList[]>) => {
if (data.body) {
this.myWatchLists = data.body;
if(this.myWatchLists.length > 0) {
this.currentWatchlist = this.myWatchLists[0].name
}
}
})
}
else { this.myWatchLists = undefined; }
});
}
public getMyWatchLists(): IUserWatchList[]| undefined {
return this.myWatchLists;
}
ngOnInit(): void {
}
ngOnDestroy(): void {
if (this.authSubscription) {
this.authSubscription.unsubscribe();
}
}
}
<div > <div >
<div *ngFor="let watchList of getMyWatchLists()">{{watchList.name}} <button class="btn btn-outline-primary mr-2" id="dropdownManual" ngbDropdownAnchor>Toggle dropdown</button>
</div> <div ngbDropdownMenu aria-labelledby="dropdownManual" >
<button ngbDropdownItem *ngFor="let watchList of getMyWatchLists()">{{watchList.name}}</button>
</div>
</div> </div>
import { Component, OnDestroy, OnInit } from '@angular/core'; import { Component } from '@angular/core';
import { HttpResponse } from '@angular/common/http'; import {WatchlistManager} from 'app/shared/watchlist/watchlist-manager';
import { UserWatchListService } from '../entities/user-watch-list/user-watch-list.service';
import { IUserWatchList } from 'app/shared/model/user-watch-list.model'; import { IUserWatchList } from 'app/shared/model/user-watch-list.model';
import { AccountService } from 'app/core/auth/account.service';
import { Subscription } from 'rxjs';
import { Account } from 'app/core/user/account.model';
@Component({ @Component({
...@@ -12,53 +8,19 @@ import { Account } from 'app/core/user/account.model'; ...@@ -12,53 +8,19 @@ import { Account } from 'app/core/user/account.model';
templateUrl: './watchlist.component.html', templateUrl: './watchlist.component.html',
styleUrls: ['./watchlist.component.scss'], styleUrls: ['./watchlist.component.scss'],
}) })
export class WatchlistComponent implements OnInit, OnDestroy { export class WatchlistComponent {
account: Account | null = null;
authSubscription?: Subscription;
myWatchLists: IUserWatchList[] | undefined; myWatchLists: IUserWatchList[] | undefined;
constructor( constructor(
protected watchListService: UserWatchListService, private watchlistManager: WatchlistManager,
private accountService: AccountService,
) { ) {
} }
getMyWatchLists(): IUserWatchList[] { getMyWatchLists(): IUserWatchList[]|undefined {
if(!this.isAuthenticated()) return []; return this.watchlistManager.getMyWatchLists();
if (!this.myWatchLists) {
this.watchListService.findMyWatchlists().subscribe((data: HttpResponse<IUserWatchList[]>) => {
if (data.body) {
this.myWatchLists = data.body;
/*
this.myWatchLists = [];
for (let i = 0; i < data.body.length; i++) {
this.myWatchLists.push(data.body[i]);
}
*/
}
})
return[];
} else {
return this.myWatchLists;
}
}
ngOnInit(): void {
this.authSubscription = this.accountService.getAuthenticationState().subscribe(account => (this.account = account));
} }
isAuthenticated(): boolean {
return this.accountService.isAuthenticated();
}
ngOnDestroy(): void {
if (this.authSubscription) {
this.authSubscription.unsubscribe();
}
}
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment