-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #690 from Maximbndrnk/master
add profiles feature (issue #678)
- Loading branch information
Showing
46 changed files
with
1,114 additions
and
57 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
grails-app/assets/javascripts/streama/controllers/subProfiles-ctrl.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
'use strict'; | ||
|
||
angular.module('streama').controller('subProfilesCtrl', | ||
function ($scope, apiService, $rootScope, userService, localStorageService, $state, profileService) { | ||
|
||
$scope.profile = { | ||
profileName: '', | ||
profileLanguage: 'en', | ||
isChild: false, | ||
avatarColor: '0b74b2' | ||
}; | ||
$scope.standardColor = '0b74b2'; | ||
$scope.existingProfiles = []; | ||
$scope.loading = true; | ||
$scope.isManageProfiles = false; | ||
$scope.isEditProfile = false; | ||
$scope.isCreateProfile = false; | ||
$scope.availableColors = [ | ||
'0b74b2','ba1c56','099166','d1b805','c03da7', | ||
'488f16','d36e10','4b4b4b','3a328b','b81f1f' | ||
]; | ||
|
||
profileService.getUserProfiles().success( | ||
function(data) { | ||
$scope.existingProfiles = data; | ||
} | ||
); | ||
$scope.setCurrentProfile = profileService.setCurrentProfile; | ||
|
||
$scope.setProfileColor = function(color){ | ||
$scope.profile.avatarColor = color; | ||
}; | ||
|
||
$scope.toggleManageProfiles = function(){ | ||
$scope.isManageProfiles = !$scope.isManageProfiles; | ||
}; | ||
|
||
$scope.goToEditProfile = function(profile){ | ||
$scope.isEditProfile = !$scope.isEditProfile; | ||
$scope.profile = profile; | ||
}; | ||
|
||
$scope.goToCreateProfile = function(){ | ||
$scope.isCreateProfile = !$scope.isCreateProfile; | ||
$scope.profile = { | ||
profileName: '', | ||
profileLanguage: 'en', | ||
isChild: false, | ||
avatarColor: '0b74b2' | ||
} | ||
}; | ||
|
||
$scope.deleteProfile = function(){ | ||
if($scope.existingProfiles.length === 1){ | ||
alertify.error("You must have at least ONE profile!"); | ||
return; | ||
} | ||
if($scope.profile.id === profileService.getCurrentProfile().id){ | ||
alertify.error("You currently use this profile! Change profile first"); | ||
return; | ||
} | ||
if(!$scope.profile.id){ | ||
return; | ||
} | ||
apiService.profile.delete($scope.profile.id) | ||
.success(function () { | ||
alertify.success('Profile Deleted!'); | ||
$scope.getAllProfiles(); | ||
$scope.loading = false; | ||
$scope.refreshStates(); | ||
}) | ||
.error(function (data) { | ||
alertify.error(data.message); | ||
$scope.loading = false; | ||
}); | ||
}; | ||
|
||
$scope.refreshStates = function(){ | ||
$scope.isEditProfile = false; | ||
$scope.isCreateProfile = false; | ||
}; | ||
|
||
$scope.saveProfile = function(){ | ||
if (!$scope.profile.profileName) { | ||
return; | ||
} | ||
var saveProfileEndpoint; | ||
if ($scope.profile.id) { | ||
saveProfileEndpoint = apiService.profile.update; | ||
}else { | ||
saveProfileEndpoint = apiService.profile.save; | ||
} | ||
saveProfileEndpoint($scope.profile) | ||
.success(function () { | ||
alertify.success($scope.profile.id ? 'Profile Updated!' : 'Profile Created!'); | ||
$scope.getAllProfiles(); | ||
$scope.loading = false; | ||
$rootScope.$broadcast('streama.profiles.onChange'); | ||
}) | ||
.error(function (data) { | ||
alertify.error(data.message); | ||
$scope.loading = false; | ||
}); | ||
}; | ||
|
||
$scope.getAllProfiles = function () { | ||
apiService.profile.getUserProfiles() | ||
.success(function (data) { | ||
$scope.existingProfiles = data; | ||
$scope.refreshStates(); | ||
}) | ||
.error(function (data) { | ||
alertify.error(data.message); | ||
$scope.loading = false; | ||
}); | ||
}; | ||
|
||
$scope.showPreviewProfiles = function() { | ||
return !$scope.isManageProfiles && !($scope.isEditProfile || $scope.isCreateProfile); | ||
}; | ||
|
||
$scope.showEditProfiles = function() { | ||
return $scope.isManageProfiles && !($scope.isEditProfile || $scope.isCreateProfile); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
grails-app/assets/javascripts/streama/services/profile-service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
angular.module('streama').factory('profileService', function (localStorageService, apiService, $state, $rootScope, $translate) { | ||
|
||
function setCurrentProfile(profile) { | ||
localStorageService.set('currentProfile', profile); | ||
$rootScope.currentProfile = profile; | ||
$state.go('dash', {}, {reload: true}); | ||
$translate.use(_.get($rootScope, 'currentProfile.profileLanguage') || _.get($rootScope, 'currentUser.language') || 'en'); | ||
} | ||
|
||
function getCurrentProfile() { | ||
return localStorageService.get('currentProfile') || null; | ||
} | ||
|
||
function getUserProfiles() { | ||
return apiService.profile.getUserProfiles(); | ||
} | ||
|
||
return { | ||
setCurrentProfile: setCurrentProfile, | ||
getCurrentProfile: getCurrentProfile, | ||
getUserProfiles: getUserProfiles | ||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.