From bb0b432bab7e4e5ae613bf14cdd7338dc0755c6e Mon Sep 17 00:00:00 2001 From: Pepe Becker Date: Thu, 21 Nov 2019 18:05:47 +0100 Subject: [PATCH] Create RoomUsersList component --- src/angularjs/abstract/abstract-users-list.ts | 8 ++--- .../components/friends-list.component.ts | 11 ++---- src/angularjs/components/index.ts | 1 + .../components/online-users-list.component.ts | 9 ++--- .../components/room-users-list.component.ts | 35 +++++++++++++++++++ src/assets/partials/chat-room.html | 4 +-- src/assets/partials/user-list.html | 2 +- 7 files changed, 47 insertions(+), 23 deletions(-) create mode 100755 src/angularjs/components/room-users-list.component.ts diff --git a/src/angularjs/abstract/abstract-users-list.ts b/src/angularjs/abstract/abstract-users-list.ts index 5a8e2c9..63e032c 100755 --- a/src/angularjs/abstract/abstract-users-list.ts +++ b/src/angularjs/abstract/abstract-users-list.ts @@ -8,13 +8,13 @@ import { IUserStore } from '../persistence/user-store'; import { IRoomStore } from '../persistence/room-store'; import { IRoomCreator } from '../services/room-creator'; import { IRoomOpenQueue } from '../services/room-open-queue'; +import { IProfileBox } from '../services/profile-box.service'; export class AbstractUsersListController { - static $inject = ['$scope', 'Cache', 'UserStore', 'RoomStore', 'RoomCreator', 'RoomOpenQueue']; + static $inject = ['$scope', 'Cache', 'UserStore', 'RoomStore', 'RoomCreator', 'RoomOpenQueue', 'ProfileBox']; room: IRoom; - allUsers = Array(); users = Array(); constructor( @@ -24,7 +24,7 @@ export class AbstractUsersListController { protected RoomStore: IRoomStore, protected RoomCreator: IRoomCreator, protected RoomOpenQueue: IRoomOpenQueue, - + protected ProfileBox: IProfileBox, ) { if (this.constructor === AbstractUsersListController) { throw new Error('AbstractUsersListController can\'t be instantiated.'); @@ -56,7 +56,7 @@ export class AbstractUsersListController { } showProfileBox(uid: string) { - throw new Error('Method \'showProfileBox(uid: string)\' must be implemented.'); + this.ProfileBox.show(uid); } userClicked(user: IUser) { diff --git a/src/angularjs/components/friends-list.component.ts b/src/angularjs/components/friends-list.component.ts index 8bd7852..9914298 100755 --- a/src/angularjs/components/friends-list.component.ts +++ b/src/angularjs/components/friends-list.component.ts @@ -6,7 +6,6 @@ import { ArrayUtils } from '../services/array-utils'; import { Log } from '../services/log'; import { IUser } from '../entities/user'; import { IOnlineConnector } from '../connectors/online-connector'; -import { IRoom } from '../entities/room'; import { ISearch } from '../services/search.service'; import { FriendsTab } from '../keys/tab-keys'; import { IFriendsConnector } from '../connectors/friend-connector'; @@ -21,9 +20,7 @@ export class FriendsListController extends AbstractUsersListController { static $inject = ['$scope', '$timeout', 'Cache', 'UserStore', 'RoomStore', 'RoomCreator', 'RoomOpenQueue', 'OnlineConnector', 'FriendsConnector', 'Search', 'ProfileBox']; - room: IRoom; allUsers = Array(); - users = Array(); constructor( protected $scope: ng.IScope, @@ -36,9 +33,9 @@ export class FriendsListController extends AbstractUsersListController { protected OnlineConnector: IOnlineConnector, protected FriendsConnector: IFriendsConnector, protected Search: ISearch, - private ProfileBox: IProfileBox, + protected ProfileBox: IProfileBox, ) { - super($scope, Cache, UserStore, RoomStore, RoomCreator, RoomOpenQueue); + super($scope, Cache, UserStore, RoomStore, RoomCreator, RoomOpenQueue, ProfileBox); $scope.$on(N.FriendAdded, () => { Log.notification(N.FriendAdded, 'FriendsListController'); @@ -89,10 +86,6 @@ export class FriendsListController extends AbstractUsersListController { }); } - showProfileBox(uid: string) { - this.ProfileBox.show(uid); - } - } angular.module('myApp.components').component('friendsList', { diff --git a/src/angularjs/components/index.ts b/src/angularjs/components/index.ts index 5743083..953cc5b 100644 --- a/src/angularjs/components/index.ts +++ b/src/angularjs/components/index.ts @@ -6,3 +6,4 @@ import './online-users-list.component'; import './profile-box.component'; import './public-rooms-list.component'; import './room-list-box.component'; +import './room-users-list.component'; diff --git a/src/angularjs/components/online-users-list.component.ts b/src/angularjs/components/online-users-list.component.ts index 3f0e61f..0889866 100755 --- a/src/angularjs/components/online-users-list.component.ts +++ b/src/angularjs/components/online-users-list.component.ts @@ -20,7 +20,6 @@ class OnlineUsersListController extends AbstractUsersListController { static $inject = ['$scope', '$timeout', 'OnlineConnector', 'Search', 'Cache', 'UserStore', 'RoomStore', 'RoomCreator', 'RoomOpenQueue', 'ProfileBox']; allUsers = Array(); - users = Array(); constructor( protected $scope: ng.IScope, @@ -32,9 +31,9 @@ class OnlineUsersListController extends AbstractUsersListController { protected RoomStore: IRoomStore, protected RoomCreator: IRoomCreator, protected RoomOpenQueue: IRoomOpenQueue, - private ProfileBox: IProfileBox, + protected ProfileBox: IProfileBox, ) { - super($scope, Cache, UserStore, RoomStore, RoomCreator, RoomOpenQueue); + super($scope, Cache, UserStore, RoomStore, RoomCreator, RoomOpenQueue, ProfileBox); $scope.$on(N.OnlineUserAdded, () => { Log.notification(N.OnlineUserAdded, 'OnlineUsersListController'); @@ -61,10 +60,6 @@ class OnlineUsersListController extends AbstractUsersListController { }); } - showProfileBox(uid: string) { - this.ProfileBox.show(uid); - } - } angular.module('myApp.components').component('onlineUsersList', { diff --git a/src/angularjs/components/room-users-list.component.ts b/src/angularjs/components/room-users-list.component.ts new file mode 100755 index 0000000..da49e8c --- /dev/null +++ b/src/angularjs/components/room-users-list.component.ts @@ -0,0 +1,35 @@ +import * as angular from 'angular'; + +import { AbstractUsersListController } from '../abstract/abstract-users-list'; +import { ArrayUtils } from '../services/array-utils'; + +export class RoomUsersListController extends AbstractUsersListController { + + $onChanges({ room }: ng.IOnChangesObject) { + if (angular.isDefined(room)) { + this.updateList(); + } + } + + updateList() { + this.users = ArrayUtils.objectToArray(this.room.getUsers()); + + // Sort the array alphabetically + this.users.sort((user1, user2) => { + if (user1.getName() !== user2.getName()) { + return user1.getName() > user2.getName() ? 1 : -1; + } + return 0; + }); + } + +} + +angular.module('myApp.components').component('roomUsersList', { + templateUrl: '/assets/partials/user-list.html', + controller: RoomUsersListController, + controllerAs: 'ctrl', + bindings: { + room: '<' + }, +}); diff --git a/src/assets/partials/chat-room.html b/src/assets/partials/chat-room.html index f88eb89..f6a3666 100755 --- a/src/assets/partials/chat-room.html +++ b/src/assets/partials/chat-room.html @@ -34,8 +34,8 @@
- - + +
diff --git a/src/assets/partials/user-list.html b/src/assets/partials/user-list.html index a27941f..fe70b55 100755 --- a/src/assets/partials/user-list.html +++ b/src/assets/partials/user-list.html @@ -4,7 +4,7 @@ data-ng-mouseleave="ctrl.showProfileBox(null)"> + data-draggable-user="aUser" data-ng-click="ctrl.userClicked(aUser)">