From 8a358d4bcbffbb0f0cc83f912bf5009ff054f3e7 Mon Sep 17 00:00:00 2001 From: Dale Zak Date: Wed, 16 May 2018 12:27:01 -0600 Subject: [PATCH] Added group and person component for #111 --- src/app/app.module.ts | 4 ++ src/components/group-row/group-row.html | 12 +++++ src/components/group-row/group-row.module.ts | 17 +++++++ src/components/group-row/group-row.scss | 3 ++ src/components/group-row/group-row.ts | 47 +++++++++++++++++++ src/components/person-row/person-row.html | 11 +++++ .../person-row/person-row.module.ts | 20 ++++++++ src/components/person-row/person-row.scss | 3 ++ src/components/person-row/person-row.ts | 46 ++++++++++++++++++ src/models/person.ts | 1 + src/pages/group-list/group-list.html | 8 ++-- src/pages/group-list/group-list.module.ts | 2 + src/pages/group-list/group-list.ts | 31 ++++++++++++ src/pages/person-edit/person-edit.module.ts | 2 + src/pages/person-list/person-list.html | 14 ++---- src/pages/person-list/person-list.module.ts | 2 + 16 files changed, 207 insertions(+), 16 deletions(-) create mode 100644 src/components/group-row/group-row.html create mode 100644 src/components/group-row/group-row.module.ts create mode 100644 src/components/group-row/group-row.scss create mode 100644 src/components/group-row/group-row.ts create mode 100644 src/components/person-row/person-row.html create mode 100644 src/components/person-row/person-row.module.ts create mode 100644 src/components/person-row/person-row.scss create mode 100644 src/components/person-row/person-row.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 61b969cd..ee57a324 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -94,6 +94,8 @@ import { SendViaModule } from '../components/send-via/send-via.module'; import { ColorPickerModule } from '../components/color-picker/color-picker.module'; import { PersonAvatarModule } from '../components/person-avatar/person-avatar.module'; import { CheckinCardModule } from '../components/checkin-card/checkin-card.module'; +import { PersonRowModule } from '../components/person-row/person-row.module'; +import { GroupRowModule } from '../components/group-row/group-row.module'; import { LoggerProvider } from '../providers/logger/logger'; import { ApiProvider } from '../providers/api/api'; @@ -116,6 +118,8 @@ import { CameraProvider } from '../providers/camera/camera'; ColorPickerModule, SendViaModule, CheckinCardModule, + PersonRowModule, + GroupRowModule, GroupListModule, GroupEditModule, GroupDetailsModule, diff --git a/src/components/group-row/group-row.html b/src/components/group-row/group-row.html new file mode 100644 index 00000000..3fd0588c --- /dev/null +++ b/src/components/group-row/group-row.html @@ -0,0 +1,12 @@ + + + +

{{group.name}}

+

{{group.member_count || 0}} people

+
+ + + +
diff --git a/src/components/group-row/group-row.module.ts b/src/components/group-row/group-row.module.ts new file mode 100644 index 00000000..ca681859 --- /dev/null +++ b/src/components/group-row/group-row.module.ts @@ -0,0 +1,17 @@ +import { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; + +import { GroupRowComponent } from './group-row'; + +@NgModule({ + declarations: [ + GroupRowComponent, + ], + imports: [ + IonicPageModule.forChild(GroupRowComponent), + ], + exports: [ + GroupRowComponent + ] +}) +export class GroupRowModule {} diff --git a/src/components/group-row/group-row.scss b/src/components/group-row/group-row.scss new file mode 100644 index 00000000..8c86d2d4 --- /dev/null +++ b/src/components/group-row/group-row.scss @@ -0,0 +1,3 @@ +group-row { + +} diff --git a/src/components/group-row/group-row.ts b/src/components/group-row/group-row.ts new file mode 100644 index 00000000..8676c8e0 --- /dev/null +++ b/src/components/group-row/group-row.ts @@ -0,0 +1,47 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core'; + +import { Group } from '../../models/group'; +import { Person } from '../../models/person'; + +@Component({ + selector: 'group-row', + templateUrl: 'group-row.html' +}) +export class GroupRowComponent { + + @Input() + group:Group; + + @Input() + user:Person; + + @Input() + selected:boolean = false; + + @Output() + rowSelected = new EventEmitter(); + + @Output() + removeSelected = new EventEmitter(); + + hasRowSelected:boolean = false; + + hasRemoveSelected:boolean = false; + + constructor() { + } + + ngOnInit() { + this.hasRowSelected = this.rowSelected && this.rowSelected.observers.length > 0; + this.hasRemoveSelected = this.removeSelected && this.removeSelected.observers.length > 0; + } + + onRowSelected(event:any) { + this.rowSelected.emit(); + } + + onRemoveSelected(event:any) { + this.removeSelected.emit(); + } + +} diff --git a/src/components/person-row/person-row.html b/src/components/person-row/person-row.html new file mode 100644 index 00000000..204779b1 --- /dev/null +++ b/src/components/person-row/person-row.html @@ -0,0 +1,11 @@ + + + +

{{person.name}}

+
+ + + +
diff --git a/src/components/person-row/person-row.module.ts b/src/components/person-row/person-row.module.ts new file mode 100644 index 00000000..96dd71ad --- /dev/null +++ b/src/components/person-row/person-row.module.ts @@ -0,0 +1,20 @@ +import { NgModule } from '@angular/core'; +import { IonicPageModule } from 'ionic-angular'; + +import { PersonRowComponent } from './person-row'; + +import { PersonAvatarModule } from '../../components/person-avatar/person-avatar.module'; + +@NgModule({ + declarations: [ + PersonRowComponent, + ], + imports: [ + PersonAvatarModule, + IonicPageModule.forChild(PersonRowComponent), + ], + exports: [ + PersonRowComponent + ] +}) +export class PersonRowModule {} diff --git a/src/components/person-row/person-row.scss b/src/components/person-row/person-row.scss new file mode 100644 index 00000000..a5dad4ec --- /dev/null +++ b/src/components/person-row/person-row.scss @@ -0,0 +1,3 @@ +person-row { + +} diff --git a/src/components/person-row/person-row.ts b/src/components/person-row/person-row.ts new file mode 100644 index 00000000..b533b070 --- /dev/null +++ b/src/components/person-row/person-row.ts @@ -0,0 +1,46 @@ +import { Component, Input, Output, EventEmitter } from '@angular/core'; + +import { Person } from '../../models/person'; + +@Component({ + selector: 'person-row', + templateUrl: 'person-row.html' +}) +export class PersonRowComponent { + + @Input() + person:Person; + + @Input() + user:Person; + + @Input() + selected:boolean = false; + + @Output() + rowSelected = new EventEmitter(); + + @Output() + removeSelected = new EventEmitter(); + + hasRowSelected:boolean = false; + + hasRemoveSelected:boolean = false; + + constructor() { + } + + ngOnInit() { + this.hasRowSelected = this.rowSelected && this.rowSelected.observers.length > 0; + this.hasRemoveSelected = this.removeSelected && this.removeSelected.observers.length > 0; + } + + onRowSelected(event:any) { + this.rowSelected.emit(); + } + + onRemoveSelected(event:any) { + this.removeSelected.emit(); + } + +} diff --git a/src/models/person.ts b/src/models/person.ts index 456896e0..b1d94c26 100644 --- a/src/models/person.ts +++ b/src/models/person.ts @@ -35,6 +35,7 @@ export class Person extends Model { for (let _checkin of data.checkins) { console.log(`Checkin ${JSON.stringify(_checkin)}`); let checkin = new Checkin(_checkin); + //TODO verify this is correct logic to re-use person attributes checkin.user_id = this.id; checkin.user_name = this.name; checkin.user_initials = this.initials; diff --git a/src/pages/group-list/group-list.html b/src/pages/group-list/group-list.html index d28ebbc7..1f9c510e 100644 --- a/src/pages/group-list/group-list.html +++ b/src/pages/group-list/group-list.html @@ -23,11 +23,9 @@

There currently are no Groups...

- - -

{{group.name}}

-

{{group.member_count || 0}} people

-
+
diff --git a/src/pages/group-list/group-list.module.ts b/src/pages/group-list/group-list.module.ts index 926bb951..a32ce939 100644 --- a/src/pages/group-list/group-list.module.ts +++ b/src/pages/group-list/group-list.module.ts @@ -5,6 +5,7 @@ import { GroupListPage } from './group-list'; import { GroupEditModule } from '../../pages/group-edit/group-edit.module'; import { GroupDetailsModule } from '../../pages/group-details/group-details.module'; +import { GroupRowModule } from '../../components/group-row/group-row.module'; @NgModule({ declarations: [ @@ -13,6 +14,7 @@ import { GroupDetailsModule } from '../../pages/group-details/group-details.modu imports: [ GroupEditModule, GroupDetailsModule, + GroupRowModule, IonicPageModule.forChild(GroupListPage), ], exports: [ diff --git a/src/pages/group-list/group-list.ts b/src/pages/group-list/group-list.ts index 1cb75c72..329417de 100644 --- a/src/pages/group-list/group-list.ts +++ b/src/pages/group-list/group-list.ts @@ -205,6 +205,37 @@ export class GroupListPage extends BasePage { }); } + private removeGroup(group:Group) { + this.logger.info(this, "removeGroup", group); + let loading = this.showLoading("Removing..."); + this.api.deleteGroup(this.organization, group).then((deleted:any) => { + if (this.mobile) { + this.database.removeGroup(this.organization, group).then((removed:any) => { + let index = this.organization.groups.indexOf(group); + if (index > -1) { + this.organization.groups.splice(index, 1); + } + loading.dismiss(); + }, + (error:any) => { + loading.dismiss(); + this.showAlert("Problem Removing Group", error); + }); + } + else { + let index = this.organization.groups.indexOf(group); + if (index > -1) { + this.organization.groups.splice(index, 1); + } + loading.dismiss(); + } + }, + (error:any) => { + loading.dismiss(); + this.showAlert("Problem Removing Group", error); + }); + } + private showGroup(group:Group) { this.logger.info(this, "showGroup", group); this.showPage(GroupDetailsPage, { diff --git a/src/pages/person-edit/person-edit.module.ts b/src/pages/person-edit/person-edit.module.ts index 707f15b8..76992b10 100644 --- a/src/pages/person-edit/person-edit.module.ts +++ b/src/pages/person-edit/person-edit.module.ts @@ -5,6 +5,7 @@ import { PersonEditPage } from './person-edit'; import { DateTimeModule } from '../../pipes/date-time/date-time.module'; import { PersonAvatarModule } from '../../components/person-avatar/person-avatar.module'; +import { PersonRowModule } from '../../components/person-row/person-row.module'; @NgModule({ declarations: [ @@ -12,6 +13,7 @@ import { PersonAvatarModule } from '../../components/person-avatar/person-avatar ], imports: [ DateTimeModule, + PersonRowModule, PersonAvatarModule, IonicPageModule.forChild(PersonEditPage), ], diff --git a/src/pages/person-list/person-list.html b/src/pages/person-list/person-list.html index a89a29bd..23c20f6b 100644 --- a/src/pages/person-list/person-list.html +++ b/src/pages/person-list/person-list.html @@ -19,17 +19,9 @@ - - - -

{{_person.name}}

-
- - - -
+
diff --git a/src/pages/person-list/person-list.module.ts b/src/pages/person-list/person-list.module.ts index fa975a0b..27f59394 100644 --- a/src/pages/person-list/person-list.module.ts +++ b/src/pages/person-list/person-list.module.ts @@ -8,6 +8,7 @@ import { PersonInviteModule } from '../../pages/person-invite/person-invite.modu import { PersonImportModule } from '../../pages/person-import/person-import.module'; import { PersonAvatarModule } from '../../components/person-avatar/person-avatar.module'; +import { PersonRowModule } from '../../components/person-row/person-row.module'; @NgModule({ declarations: [ @@ -15,6 +16,7 @@ import { PersonAvatarModule } from '../../components/person-avatar/person-avatar ], imports: [ PersonAvatarModule, + PersonRowModule, PersonEditModule, PersonDetailsModule, PersonInviteModule,