diff --git a/src/app/_services/account.service.ts b/src/app/_services/account.service.ts index 073d3f8b4..77bf4fa73 100644 --- a/src/app/_services/account.service.ts +++ b/src/app/_services/account.service.ts @@ -40,15 +40,15 @@ export class AccountService { this.currentUserSource.next(undefined); } - register(model: {username: string, password: string, isAdmin?: boolean}) { + register(model: {username: string, password: string, isAdmin?: boolean}, login = false) { if (model?.isAdmin) { model.isAdmin = false; } return this.httpClient.post(this.baseUrl + 'account/register', model).pipe( map((user: User) => { - if (user) { - this.setCurrentUser(user); + if (user && login) { + //this.setCurrentUser(user); // Register should not act as if a user has logged in } return user; diff --git a/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.html b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.html new file mode 100644 index 000000000..70da5d876 --- /dev/null +++ b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.html @@ -0,0 +1 @@ +

library-editor-modal works!

diff --git a/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.scss b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.spec.ts b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.spec.ts new file mode 100644 index 000000000..35a606e36 --- /dev/null +++ b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LibraryEditorModalComponent } from './library-editor-modal.component'; + +describe('LibraryEditorModalComponent', () => { + let component: LibraryEditorModalComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ LibraryEditorModalComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(LibraryEditorModalComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.ts b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.ts new file mode 100644 index 000000000..920cca0a0 --- /dev/null +++ b/src/app/admin/_modals/library-editor-modal/library-editor-modal.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-library-editor-modal', + templateUrl: './library-editor-modal.component.html', + styleUrls: ['./library-editor-modal.component.scss'] +}) +export class LibraryEditorModalComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/src/app/admin/admin.module.ts b/src/app/admin/admin.module.ts index 49e49c6b0..9400c3c62 100644 --- a/src/app/admin/admin.module.ts +++ b/src/app/admin/admin.module.ts @@ -5,15 +5,18 @@ import { DashboardComponent } from './dashboard/dashboard.component'; import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; import { ManageLibraryComponent } from './manage-library/manage-library.component'; import { ManageUsersComponent } from './manage-users/manage-users.component'; +import { LibraryEditorModalComponent } from './_modals/library-editor-modal/library-editor-modal.component'; +import { SharedModule } from '../shared/shared.module'; @NgModule({ - declarations: [ManageUsersComponent, DashboardComponent, ManageLibraryComponent], + declarations: [ManageUsersComponent, DashboardComponent, ManageLibraryComponent, LibraryEditorModalComponent], imports: [ CommonModule, AdminRoutingModule, - NgbNavModule + NgbNavModule, + SharedModule ], providers: [] }) diff --git a/src/app/admin/manage-library/manage-library.component.ts b/src/app/admin/manage-library/manage-library.component.ts index 8de8a30c6..ccd0859de 100644 --- a/src/app/admin/manage-library/manage-library.component.ts +++ b/src/app/admin/manage-library/manage-library.component.ts @@ -3,6 +3,7 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { DirectoryPickerComponent, DirectoryPickerResult } from 'src/app/directory-picker/directory-picker.component'; import { Library } from 'src/app/_models/library'; import { LibraryService } from 'src/app/_services/library.service'; +import { LibraryEditorModalComponent } from '../_modals/library-editor-modal/library-editor-modal.component'; @Component({ selector: 'app-manage-library', @@ -23,6 +24,10 @@ export class ManageLibraryComponent implements OnInit { } + addLibrary() { + const modalRef = this.modalService.open(LibraryEditorModalComponent); + } + addFolder(library: string) { const modalRef = this.modalService.open(DirectoryPickerComponent); diff --git a/src/app/admin/manage-users/manage-users.component.html b/src/app/admin/manage-users/manage-users.component.html index 8313dc75f..a9b483afd 100644 --- a/src/app/admin/manage-users/manage-users.component.html +++ b/src/app/admin/manage-users/manage-users.component.html @@ -3,18 +3,22 @@

Members

-
+
-
    +
    • +
      -
      Name: {{member.username | titlecase}}
      -
      Sharing: {{member?.libraries ? member?.libraries : 'None'}}
      +
      Name: {{member.username | titlecase}} (Admin)
      +
      Sharing: {{member?.libraries ? member?.libraries : 'None'}}
      Last Active: {{member.lastActive | date}}
      +
      - - +
    + + +
\ No newline at end of file diff --git a/src/app/admin/manage-users/manage-users.component.ts b/src/app/admin/manage-users/manage-users.component.ts index fc53075ec..9121d1881 100644 --- a/src/app/admin/manage-users/manage-users.component.ts +++ b/src/app/admin/manage-users/manage-users.component.ts @@ -1,8 +1,11 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { take } from 'rxjs/operators'; import { DirectoryPickerComponent, DirectoryPickerResult } from 'src/app/directory-picker/directory-picker.component'; import { MemberService } from 'src/app/member.service'; import { Member } from 'src/app/_models/member'; +import { User } from 'src/app/_models/user'; +import { AccountService } from 'src/app/_services/account.service'; @Component({ selector: 'app-manage-users', @@ -12,17 +15,38 @@ import { Member } from 'src/app/_models/member'; export class ManageUsersComponent implements OnInit { members: Member[] = []; - closeResult = ''; // Debug code - @ViewChild('content') content: any; + loggedInUsername = ''; - constructor(private memberService: MemberService) { } + // Create User functionality + createMemberToggle = false; + + constructor(private memberService: MemberService, public accountService: AccountService) { + this.accountService.currentUser$.pipe(take(1)).subscribe((user: User) => { + this.loggedInUsername = user.username; + }); + } ngOnInit(): void { console.log('User Component'); + this.loadMembers(); + } + + loadMembers() { this.memberService.getMembers().subscribe(members => { this.members = members; }); } - + canEditMember(member: Member): boolean { + return this.loggedInUsername !== member.username; + } + + createMember() { + this.createMemberToggle = true; + } + + onMemberCreated(success: boolean) { + this.createMemberToggle = false; + this.loadMembers(); + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index ed0cc879c..bbaf241c0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -15,6 +15,7 @@ import { ToastrModule } from 'ngx-toastr'; import { ErrorInterceptor } from './_interceptors/error.interceptor'; import { LibraryComponent } from './library/library.component'; import { DirectoryPickerComponent } from './directory-picker/directory-picker.component'; +import { SharedModule } from './shared/shared.module'; @@ -25,7 +26,7 @@ import { DirectoryPickerComponent } from './directory-picker/directory-picker.co NavHeaderComponent, UserLoginComponent, LibraryComponent, - DirectoryPickerComponent + DirectoryPickerComponent, ], imports: [ HttpClientModule, @@ -34,6 +35,7 @@ import { DirectoryPickerComponent } from './directory-picker/directory-picker.co BrowserAnimationsModule, ReactiveFormsModule, NgbModule, + SharedModule, ToastrModule.forRoot({ positionClass: 'toast-bottom-right' }), diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 2c1572356..d9f442777 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -1,30 +1,9 @@ -

Welcome to Kativa

Please create an admin account for yourself to start your reading journey.

-
-

Error:

-
    - -
-
-
-
- - -
- -
- - -
- - -
+
diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 5e6a6387a..16cc040e3 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -38,19 +38,13 @@ export class HomeComponent implements OnInit { }); } }); - } - register() { - this.model.isAdmin = this.firstTimeFlow; - console.log('Registering: ', this.model); - this.accountService.register(this.model).subscribe(resp => { + onAdminCreated(success: boolean) { + if (success) { this.router.navigateByUrl('/library'); - }, err => { - console.log('validation errors from interceptor', err); - //this.errors = err; - }); + } } } diff --git a/src/app/library/library.component.ts b/src/app/library/library.component.ts index 6376e53f4..2f302d352 100644 --- a/src/app/library/library.component.ts +++ b/src/app/library/library.component.ts @@ -1,7 +1,10 @@ import { Component, OnInit } from '@angular/core'; import { take } from 'rxjs/operators'; +import { MemberService } from '../member.service'; +import { Library } from '../_models/library'; import { User } from '../_models/user'; import { AccountService } from '../_services/account.service'; +import { LibraryService } from '../_services/library.service'; @Component({ selector: 'app-library', @@ -11,12 +14,16 @@ import { AccountService } from '../_services/account.service'; export class LibraryComponent implements OnInit { user: User | undefined; + libraries: Library[] = []; - constructor(public accountService: AccountService) { } + constructor(public accountService: AccountService, private memberService: MemberService, private libraryService: LibraryService) { } ngOnInit(): void { this.accountService.currentUser$.pipe(take(1)).subscribe(user => { this.user = user; + // this.libraryService.getLibrariesForUser(this.user.username).subscribe(libraries => { + // this.libraries = libraries; + // }); }); } diff --git a/src/app/nav-header/nav-header.component.html b/src/app/nav-header/nav-header.component.html index 404b48c62..f0c3c822b 100644 --- a/src/app/nav-header/nav-header.component.html +++ b/src/app/nav-header/nav-header.component.html @@ -5,10 +5,7 @@ - - + @@ -16,8 +13,8 @@ diff --git a/src/app/nav-header/nav-header.component.ts b/src/app/nav-header/nav-header.component.ts index b196b8b2d..4dcdd4bcc 100644 --- a/src/app/nav-header/nav-header.component.ts +++ b/src/app/nav-header/nav-header.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; import { AccountService } from '../_services/account.service'; @Component({ @@ -8,13 +9,14 @@ import { AccountService } from '../_services/account.service'; }) export class NavHeaderComponent implements OnInit { - constructor(public accountService: AccountService) { } + constructor(public accountService: AccountService, private router: Router) { } ngOnInit(): void { } logout() { this.accountService.logout(); + this.router.navigateByUrl('/home'); } } diff --git a/src/app/shared/register-member/register-member.component.html b/src/app/shared/register-member/register-member.component.html new file mode 100644 index 000000000..4a82e058d --- /dev/null +++ b/src/app/shared/register-member/register-member.component.html @@ -0,0 +1,26 @@ +
+ +
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
\ No newline at end of file diff --git a/src/app/shared/register-member/register-member.component.scss b/src/app/shared/register-member/register-member.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/shared/register-member/register-member.component.ts b/src/app/shared/register-member/register-member.component.ts new file mode 100644 index 000000000..092addd55 --- /dev/null +++ b/src/app/shared/register-member/register-member.component.ts @@ -0,0 +1,53 @@ +import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { MemberService } from 'src/app/member.service'; +import { Member } from 'src/app/_models/member'; +import { AccountService } from 'src/app/_services/account.service'; + +@Component({ + selector: 'app-register-member', + templateUrl: './register-member.component.html', + styleUrls: ['./register-member.component.scss'] +}) +export class RegisterMemberComponent implements OnInit { + + @Output() created = new EventEmitter(); + + adminExists = false; + model: any = {}; + registerForm: FormGroup = new FormGroup({ + username: new FormControl('', [Validators.required]), + password: new FormControl('', [Validators.required]), + isAdmin: new FormControl(false, []) + }); + + constructor(private accountService: AccountService, private memberService: MemberService) { + this.memberService.getMembers().subscribe(members => { + this.adminExists = members.filter(m => m.isAdmin).length > 0; + if (!this.adminExists) { + this.registerForm.get('isAdmin')?.setValue(true); + this.model.isAdmin = true; + } + }); + } + + ngOnInit(): void { + } + + register() { + this.model.username = this.registerForm.get('username')?.value; + this.model.password = this.registerForm.get('password')?.value; + this.model.isAdmin = this.registerForm.get('isAdmin')?.value; + + this.accountService.register(this.model).subscribe(resp => { + this.created.emit(true); + }, err => { + console.log('validation errors from interceptor', err); + }); + } + + cancel() { + this.created.emit(false); + } + +} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts new file mode 100644 index 000000000..d3b94d520 --- /dev/null +++ b/src/app/shared/shared.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { RegisterMemberComponent } from './register-member/register-member.component'; +import { ReactiveFormsModule } from '@angular/forms'; + + + +@NgModule({ + declarations: [RegisterMemberComponent], + imports: [ + CommonModule, + ReactiveFormsModule + ], + exports: [ + RegisterMemberComponent + ] +}) +export class SharedModule { } diff --git a/src/app/user-login/user-login.component.ts b/src/app/user-login/user-login.component.ts index 31a72811f..6917032bc 100644 --- a/src/app/user-login/user-login.component.ts +++ b/src/app/user-login/user-login.component.ts @@ -23,11 +23,9 @@ export class UserLoginComponent implements OnInit { login() { this.model = {username: this.loginForm.get('username')?.value, password: this.loginForm.get('password')?.value}; - this.accountService.login(this.model).subscribe(user => { - if (user) { - this.loginForm.reset(); - this.router.navigateByUrl('/library'); - } + this.accountService.login(this.model).subscribe(() => { + this.loginForm.reset(); + this.router.navigateByUrl('/library'); }); }