From 28a49a9eaf79f1b05fc2f793ad264d45c017de4c Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Thu, 14 Aug 2014 11:39:03 +0200 Subject: Show avatar in profile section and added a button to select a file (not yet wired to upload service) --- webclient/rooms/rooms-controller.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'webclient/rooms/rooms-controller.js') diff --git a/webclient/rooms/rooms-controller.js b/webclient/rooms/rooms-controller.js index 293ea8bc8b..b7f19bb2b5 100644 --- a/webclient/rooms/rooms-controller.js +++ b/webclient/rooms/rooms-controller.js @@ -16,7 +16,7 @@ limitations under the License. 'use strict'; -angular.module('RoomsController', ['matrixService']) +angular.module('RoomsController', ['matrixService', 'mFileInput']) .controller('RoomsController', ['$scope', '$location', 'matrixService', function($scope, $location, matrixService) { @@ -40,7 +40,8 @@ angular.module('RoomsController', ['matrixService']) $scope.newProfileInfo = { name: matrixService.config().displayName, - avatar: matrixService.config().avatarUrl + avatar: matrixService.config().avatarUrl, + avatarFile: undefined }; $scope.linkedEmails = { @@ -163,6 +164,13 @@ angular.module('RoomsController', ['matrixService']) ); }; + + $scope.$watch("newProfileInfo.avatarFile", function(newValue, oldValue) { + if ($scope.newProfileInfo.avatarFile) { + //@TODO: Upload this HTML5 image file to somewhere + } + }); + $scope.setAvatar = function(newUrl) { console.log("Updating avatar to "+newUrl); matrixService.setProfilePictureUrl(newUrl).then( -- cgit 1.4.1 From 24bd133d9d4c9a30c4609cf6d55f02ab6f05c142 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 15:43:16 +0100 Subject: Added extra nesting .data and rename callback to be response not data --- webclient/login/login-controller.js | 4 +-- webclient/rooms/rooms-controller.js | 58 ++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 31 deletions(-) (limited to 'webclient/rooms/rooms-controller.js') diff --git a/webclient/login/login-controller.js b/webclient/login/login-controller.js index c519f7698c..015868b0b9 100644 --- a/webclient/login/login-controller.js +++ b/webclient/login/login-controller.js @@ -68,7 +68,7 @@ angular.module('LoginController', ['matrixService']) // try to login matrixService.login($scope.account.user_id, $scope.account.password).then( function(response) { - if ("access_token" in response) { + if ("access_token" in response.data) { $scope.feedback = "Login successful."; matrixService.setConfig({ homeserver: $scope.account.homeserver, @@ -79,7 +79,7 @@ angular.module('LoginController', ['matrixService']) $location.path("rooms"); } else { - $scope.feedback = "Failed to login: " + JSON.stringify(response); + $scope.feedback = "Failed to login: " + JSON.stringify(response.data); } }, function(error) { diff --git a/webclient/rooms/rooms-controller.js b/webclient/rooms/rooms-controller.js index b7f19bb2b5..d0924f5887 100644 --- a/webclient/rooms/rooms-controller.js +++ b/webclient/rooms/rooms-controller.js @@ -75,18 +75,18 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) // List all rooms joined or been invited to $scope.rooms = matrixService.rooms(); matrixService.rooms().then( - function(data) { - data = assignRoomAliases(data); + function(response) { + var data = assignRoomAliases(response.data); $scope.feedback = "Success"; $scope.rooms = data; }, - function(reason) { - $scope.feedback = "Failure: " + reason; + function(error) { + $scope.feedback = "Failure: " + error.data; }); matrixService.publicRooms().then( - function(data) { - $scope.public_rooms = assignRoomAliases(data.chunk); + function(response) { + $scope.public_rooms = assignRoomAliases(response.data.chunk); } ); }; @@ -101,14 +101,14 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) matrixService.create(room_id, visibility).then( function(response) { // This room has been created. Refresh the rooms list - console.log("Created room " + response.room_alias + " with id: "+ - response.room_id); + console.log("Created room " + response.data.room_alias + " with id: "+ + response.data.room_id); matrixService.createRoomIdToAliasMapping( - response.room_id, response.room_alias); + response.data.room_id, response.data.room_alias); $scope.refresh(); }, - function(reason) { - $scope.feedback = "Failure: " + reason; + function(error) { + $scope.feedback = "Failure: " + error.data; }); }; @@ -118,17 +118,17 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) //$location.path("room/" + room_id); matrixService.join(room_id).then( function(response) { - if (response.hasOwnProperty("room_id")) { - if (response.room_id != room_id) { - $location.path("room/" + response.room_id); + if (response.data.hasOwnProperty("room_id")) { + if (response.data.room_id != room_id) { + $location.path("room/" + response.data.room_id); return; } } $location.path("room/" + room_id); }, - function(reason) { - $scope.feedback = "Can't join room: " + reason; + function(error) { + $scope.feedback = "Can't join room: " + error.data; } ); }; @@ -136,15 +136,15 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) $scope.joinAlias = function(room_alias) { matrixService.joinAlias(room_alias).then( function(response) { - if (response.hasOwnProperty("room_id")) { - $location.path("room/" + response.room_id); + if (response.data.hasOwnProperty("room_id")) { + $location.path("room/" + response.data.room_id); return; } else { // TODO (erikj): Do something here? } }, - function(reason) { - $scope.feedback = "Can't join room: " + reason; + function(error) { + $scope.feedback = "Can't join room: " + error.data; } ); }; @@ -158,8 +158,8 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) matrixService.setConfig(config); matrixService.saveConfig(); }, - function(reason) { - $scope.feedback = "Can't update display name: " + reason; + function(error) { + $scope.feedback = "Can't update display name: " + error.data; } ); }; @@ -182,8 +182,8 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) matrixService.setConfig(config); matrixService.saveConfig(); }, - function(reason) { - $scope.feedback = "Can't update avatar: " + reason; + function(error) { + $scope.feedback = "Can't update avatar: " + error.data; } ); }; @@ -191,8 +191,8 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) $scope.linkEmail = function(email) { matrixService.linkEmail(email).then( function(response) { - if (response.success === true) { - $scope.linkedEmails.authTokenId = response.tokenId; + if (response.data.success === true) { + $scope.linkedEmails.authTokenId = response.data.tokenId; $scope.emailFeedback = "You have been sent an email."; $scope.linkedEmails.emailBeingAuthed = email; } @@ -200,8 +200,8 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) $scope.emailFeedback = "Failed to send email."; } }, - function(reason) { - $scope.emailFeedback = "Can't send email: " + reason; + function(error) { + $scope.emailFeedback = "Can't send email: " + error.data; } ); }; @@ -214,7 +214,7 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) } matrixService.authEmail(matrixService.config().user_id, tokenId, code).then( function(response) { - if ("success" in response && response.success === false) { + if ("success" in response.data && response.data.success === false) { $scope.emailFeedback = "Failed to authenticate email."; return; } -- cgit 1.4.1 From e6c62d5d7f45234ee574595eeb5ab8b7df41a1ed Mon Sep 17 00:00:00 2001 From: Emmanuel ROHEE Date: Thu, 14 Aug 2014 18:40:20 +0200 Subject: We can now upload avatar image somewhere --- webclient/rooms/rooms-controller.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'webclient/rooms/rooms-controller.js') diff --git a/webclient/rooms/rooms-controller.js b/webclient/rooms/rooms-controller.js index d0924f5887..2ce14e1d49 100644 --- a/webclient/rooms/rooms-controller.js +++ b/webclient/rooms/rooms-controller.js @@ -16,9 +16,9 @@ limitations under the License. 'use strict'; -angular.module('RoomsController', ['matrixService', 'mFileInput']) -.controller('RoomsController', ['$scope', '$location', 'matrixService', - function($scope, $location, matrixService) { +angular.module('RoomsController', ['matrixService', 'mFileInput', 'mFileUpload']) +.controller('RoomsController', ['$scope', '$location', 'matrixService', 'mFileUpload', + function($scope, $location, matrixService, mFileUpload) { $scope.rooms = []; $scope.public_rooms = []; @@ -167,7 +167,16 @@ angular.module('RoomsController', ['matrixService', 'mFileInput']) $scope.$watch("newProfileInfo.avatarFile", function(newValue, oldValue) { if ($scope.newProfileInfo.avatarFile) { - //@TODO: Upload this HTML5 image file to somewhere + console.log("Uploading new avatar file..."); + mFileUpload.uploadFile($scope.newProfileInfo.avatarFile).then( + function(url) { + $scope.newProfileInfo.avatar = url; + $scope.setAvatar($scope.newProfileInfo.avatar); + }, + function(error) { + $scope.feedback = "Can't upload image"; + } + ); } }); -- cgit 1.4.1