From f220292e24ae71d5cb4e0b4166a37e4979e4579c Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Fri, 27 Apr 2018 00:03:33 +0100 Subject: [PATCH] Added right side overlay --- client/src/app/app.component.html | 4 +- client/src/app/app.component.ts | 16 ++++--- client/src/app/app.module.ts | 6 ++- .../components/navbar/navbar.component.html | 28 ++++++----- .../app/components/navbar/navbar.component.ts | 8 +++- .../side-overlay/side-overlay.component.css | 0 .../side-overlay/side-overlay.component.html | 48 +++++++++++++++++++ .../side-overlay/side-overlay.component.ts | 40 ++++++++++++++++ .../components/sidebar/sidebar.component.ts | 2 - client/src/app/models/podcasts.models.ts | 3 +- client/src/app/reducers/profile.reducer.ts | 2 +- client/src/app/services/podcast.service.ts | 10 +++- client/src/app/services/ui-state.service.ts | 14 ++++++ server/Controllers/AuthController.cs | 2 + server/Controllers/EntryController.cs | 9 ++++ .../ViewModels/Resources/EntryViewModel.cs | 1 + server/Persistence/EntryRepository.cs | 8 ++++ server/Persistence/IEntryRepository.cs | 1 + server/Services/Auth/PodNomsUserManager.cs | 8 ++++ 19 files changed, 178 insertions(+), 32 deletions(-) create mode 100644 client/src/app/components/side-overlay/side-overlay.component.css create mode 100644 client/src/app/components/side-overlay/side-overlay.component.html create mode 100644 client/src/app/components/side-overlay/side-overlay.component.ts create mode 100644 client/src/app/services/ui-state.service.ts diff --git a/client/src/app/app.component.html b/client/src/app/app.component.html index f157053..fff9674 100644 --- a/client/src/app/app.component.html +++ b/client/src/app/app.component.html @@ -1,9 +1,9 @@
-
- -
-
+
- + + + diff --git a/client/src/app/components/navbar/navbar.component.ts b/client/src/app/components/navbar/navbar.component.ts index 91bdef6..dbdc87e 100644 --- a/client/src/app/components/navbar/navbar.component.ts +++ b/client/src/app/components/navbar/navbar.component.ts @@ -3,6 +3,7 @@ import { Component, OnInit } from '@angular/core'; import { PodnomsAuthService } from '../../services/podnoms-auth.service'; import { ProfileService } from '../../services/profile.service'; import { Observable } from 'rxjs/Observable'; +import { UiStateService } from '../../services/ui-state.service'; @Component({ selector: 'app-navbar', @@ -14,7 +15,8 @@ export class NavbarComponent implements OnInit { constructor( private _authService: PodnomsAuthService, - private _profileService: ProfileService + private _profileService: ProfileService, + private _uiStateService: UiStateService ) {} ngOnInit() { @@ -22,7 +24,9 @@ export class NavbarComponent implements OnInit { this.user$ = this._profileService.getProfile(); } } - + toggleOverlay() { + this._uiStateService.toggleOverlay(); + } logout() { this._authService.logout(); } diff --git a/client/src/app/components/side-overlay/side-overlay.component.css b/client/src/app/components/side-overlay/side-overlay.component.css new file mode 100644 index 0000000..e69de29 diff --git a/client/src/app/components/side-overlay/side-overlay.component.html b/client/src/app/components/side-overlay/side-overlay.component.html new file mode 100644 index 0000000..45c41e3 --- /dev/null +++ b/client/src/app/components/side-overlay/side-overlay.component.html @@ -0,0 +1,48 @@ + diff --git a/client/src/app/components/side-overlay/side-overlay.component.ts b/client/src/app/components/side-overlay/side-overlay.component.ts new file mode 100644 index 0000000..8c4e85c --- /dev/null +++ b/client/src/app/components/side-overlay/side-overlay.component.ts @@ -0,0 +1,40 @@ +import { Component, OnInit } from '@angular/core'; +import { UiStateService } from '../../services/ui-state.service'; +import { ProfileService } from 'app/services/profile.service'; +import { ProfileModel } from 'app/models/profile.model'; +import { PodcastEntryModel } from 'app/models/podcasts.models'; +import { Observable } from 'rxjs/Observable'; +import { PodcastService } from 'app/services/podcast.service'; +import { AudioService } from 'app/services/audio.service'; + +@Component({ + selector: 'app-side-overlay', + templateUrl: './side-overlay.component.html', + styleUrls: ['./side-overlay.component.css'] +}) +export class SideOverlayComponent implements OnInit { + user$: Observable; + entries$: Observable; + + constructor( + private _profileService: ProfileService, + private _podcastService: PodcastService, + private _uiStateService: UiStateService, + private _audioService: AudioService + ) {} + + ngOnInit() { + this._uiStateService.change.subscribe((r) => { + if (r) { + this.user$ = this._profileService.getProfile(); + this.entries$ = this._podcastService.getAllEntriesForUser(); + } + }); + } + toggleOverlay() { + this._uiStateService.toggleOverlay(); + } + playAudio(entry: PodcastEntryModel) { + this._audioService.playAudio(entry.audioUrl, entry.title); + } +} diff --git a/client/src/app/components/sidebar/sidebar.component.ts b/client/src/app/components/sidebar/sidebar.component.ts index d3c4dd6..188f267 100644 --- a/client/src/app/components/sidebar/sidebar.component.ts +++ b/client/src/app/components/sidebar/sidebar.component.ts @@ -29,7 +29,5 @@ export class SidebarComponent { this._store.dispatch(new fromPodcastActions.GetAction(podcast.slug)); return false; } - deletePodcast(podcast) { - } } diff --git a/client/src/app/models/podcasts.models.ts b/client/src/app/models/podcasts.models.ts index 26a539f..4d47f24 100644 --- a/client/src/app/models/podcasts.models.ts +++ b/client/src/app/models/podcasts.models.ts @@ -1,4 +1,3 @@ - export class PodcastModel { id?: number; title: string; @@ -23,7 +22,7 @@ export class PodcastEntryModel { processed: boolean; processingStatus?: string; processingPayload?: string; - + podcast?: PodcastModel; constructor(podcastId?: number, sourceUrl?: string) { this.podcastId = podcastId; this.sourceUrl = sourceUrl; diff --git a/client/src/app/reducers/profile.reducer.ts b/client/src/app/reducers/profile.reducer.ts index 6176415..98f77a5 100644 --- a/client/src/app/reducers/profile.reducer.ts +++ b/client/src/app/reducers/profile.reducer.ts @@ -51,4 +51,4 @@ export function reducer(state = initialState, action: profile.Actions): State { return state; } } -} \ No newline at end of file +} diff --git a/client/src/app/services/podcast.service.ts b/client/src/app/services/podcast.service.ts index 31988d9..3de9fd7 100644 --- a/client/src/app/services/podcast.service.ts +++ b/client/src/app/services/podcast.service.ts @@ -41,8 +41,14 @@ export class PodcastService { } //#endregion //#region Entries - getEntries(slug: string): any { - return this._http.get(environment.API_HOST + '/entry/all/' + slug); + + getAllEntriesForUser(): Observable { + return this._http.get( + environment.API_HOST + '/entry/users/' + ); + } + getEntries(slug: string): Observable { + return this._http.get(environment.API_HOST + '/entry/all/' + slug); } addEntry(entry: PodcastEntryModel): Observable { return this._http.post( diff --git a/client/src/app/services/ui-state.service.ts b/client/src/app/services/ui-state.service.ts new file mode 100644 index 0000000..70bfcc8 --- /dev/null +++ b/client/src/app/services/ui-state.service.ts @@ -0,0 +1,14 @@ +import { Injectable, Output, EventEmitter } from '@angular/core'; + +@Injectable() +export class UiStateService { + overlayOpen: boolean = false; + @Output() change: EventEmitter = new EventEmitter(); + + constructor() {} + + toggleOverlay() { + this.overlayOpen = !this.overlayOpen; + this.change.emit(this.overlayOpen); + } +} diff --git a/server/Controllers/AuthController.cs b/server/Controllers/AuthController.cs index bb9d5ba..ce974d9 100644 --- a/server/Controllers/AuthController.cs +++ b/server/Controllers/AuthController.cs @@ -50,6 +50,8 @@ namespace PodNoms.Api.Controllers { // check the credentials if (await _userManager.CheckPasswordAsync(userToVerify, password)) { + await _userManager.UpdateAsync(userToVerify); + return await Task.FromResult(_jwtFactory.GenerateClaimsIdentity(userName, userToVerify.Id)); } diff --git a/server/Controllers/EntryController.cs b/server/Controllers/EntryController.cs index 7f8837c..e96abba 100644 --- a/server/Controllers/EntryController.cs +++ b/server/Controllers/EntryController.cs @@ -64,6 +64,15 @@ namespace PodNoms.Api.Controllers { } } + [HttpGet("users")] + public async Task GetAllForUser() { + var entries = await _repository.GetAllForUserAsync(_applicationUser.Id); + var results = _mapper.Map, List>( + entries.OrderByDescending(e => e.Id).ToList() + ); + return Ok(results); + } + [HttpGet("all/{podcastSlug}")] public async Task GetAllForSlug(string podcastSlug) { var entries = await _repository.GetAllAsync(podcastSlug); diff --git a/server/Models/ViewModels/Resources/EntryViewModel.cs b/server/Models/ViewModels/Resources/EntryViewModel.cs index a51a884..9e5fef3 100644 --- a/server/Models/ViewModels/Resources/EntryViewModel.cs +++ b/server/Models/ViewModels/Resources/EntryViewModel.cs @@ -17,5 +17,6 @@ namespace PodNoms.Api.Models.ViewModels { public string ProcessingStatus { get; set; } public bool Processed { get; set; } public string ProcessingPayload { get; set; } + public PodcastViewModel Podcast { get; set; } } } \ No newline at end of file diff --git a/server/Persistence/EntryRepository.cs b/server/Persistence/EntryRepository.cs index a78abff..8076b46 100644 --- a/server/Persistence/EntryRepository.cs +++ b/server/Persistence/EntryRepository.cs @@ -37,6 +37,14 @@ namespace PodNoms.Api.Persistence { .ToListAsync(); return entries; } + public async Task> GetAllForUserAsync(string userId) { + var entries = await _context.PodcastEntries + .Where(e => e.Podcast.AppUser.Id == userId) + .Include(e => e.Podcast) + .ToListAsync(); + return entries; + } + public async Task AddOrUpdateAsync(PodcastEntry entry) { if (entry.Id != 0) { // _context.Entry(entry).State = EntityState.Modified diff --git a/server/Persistence/IEntryRepository.cs b/server/Persistence/IEntryRepository.cs index 009252b..c2f08c9 100644 --- a/server/Persistence/IEntryRepository.cs +++ b/server/Persistence/IEntryRepository.cs @@ -8,6 +8,7 @@ namespace PodNoms.Api.Persistence { Task GetByUidAsync(string uid); Task> GetAllAsync(int podcastId); Task> GetAllAsync(string podcastSlug); + Task> GetAllForUserAsync(string userId); Task AddOrUpdateAsync(PodcastEntry entry); Task DeleteAsync(int id); } diff --git a/server/Services/Auth/PodNomsUserManager.cs b/server/Services/Auth/PodNomsUserManager.cs index c7b3909..98ffe65 100644 --- a/server/Services/Auth/PodNomsUserManager.cs +++ b/server/Services/Auth/PodNomsUserManager.cs @@ -31,14 +31,22 @@ namespace PodNoms.Api.Services.Auth { } public override async Task CreateAsync(ApplicationUser user) { _slugify(user); + _checkName(user); await _imageify(user); return await base.CreateAsync(user); } public override async Task UpdateAsync(ApplicationUser user) { _slugify(user); + _checkName(user); await _imageify(user); return await base.UpdateAsync(user); } + private void _checkName(ApplicationUser user) { + if (string.IsNullOrEmpty(user.FirstName)) { + user.FirstName = "PodNoms"; + user.LastName = "User"; + } + } private async Task _imageify(ApplicationUser user) { if (string.IsNullOrEmpty(user.PictureUrl)) {