-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added user profile service and model.
Added initial bindings for Volume property. Architecture very messy - need to refactor. Still buggy - work not complete.
- Loading branch information
Showing
8 changed files
with
206 additions
and
43 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var baw = window.baw = window.baw || {}; | ||
|
||
|
||
baw.UserProfile = (function () { | ||
|
||
/*function makeGetter(key) { | ||
return function() { | ||
return this[key]; | ||
}; | ||
} | ||
function makeSetter(key, service) { | ||
return function(value) { | ||
if (value !== this[key]) { | ||
this[key] = value; | ||
service.updatePreferences(key, this); | ||
} | ||
}; | ||
}*/ | ||
|
||
function UserProfile(serviceReference, profile, defaultProfile) { | ||
|
||
if (!(this instanceof UserProfile)) { | ||
throw new Error("Constructor called as a function"); | ||
} | ||
|
||
var immediateSave = false; | ||
if (!profile) { | ||
profile = defaultProfile; | ||
immediateSave = true; | ||
} | ||
|
||
if (!defaultProfile) { | ||
throw new Error("A default profile must be supplied"); | ||
} | ||
|
||
// make read only properties for all profile props returned | ||
var props = Object.keys(profile) | ||
.reduce(function (state, current, index, array) { | ||
state[current] = { | ||
value: profile[current], | ||
writeable: false, | ||
enumerable: true, | ||
configurable: false | ||
}; | ||
return state; | ||
}, {}); | ||
Object.defineProperties(this, props); | ||
|
||
// now create persistence settings logic | ||
var merged = angular.extend(defaultProfile.preferences, this.preferences); | ||
for (var key in merged) { | ||
if (!merged.hasOwnProperty(key)) { | ||
return; | ||
} | ||
|
||
this.preferences[key] = merged[key]; | ||
|
||
/* | ||
Object.defineProperty(this.preferences, "_" + key, { | ||
value: merged[key], | ||
writeable: true, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
Object.defineProperty(this.preferences, key, { | ||
get: makeGetter(key), | ||
set: makeSetter(key, serviceReference), | ||
configurable: false, | ||
enumerable: true | ||
});*/ | ||
} | ||
|
||
if (immediateSave) { | ||
|
||
} | ||
|
||
} | ||
|
||
return UserProfile; | ||
})(); |
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,72 @@ | ||
var bawss = bawss || angular.module("bawApp.services", ["ngResource", "bawApp.configuration"]); | ||
|
||
bawss.factory("UserProfile", [ | ||
"$http", | ||
"conf.paths", | ||
"conf.constants", | ||
function ($http, paths, constants) { | ||
var profileUrl = paths.api.routes.user.profileAbsolute; | ||
var preferencesUrl = paths.api.routes.user.settingsAbsolute; | ||
|
||
var methods = {}; | ||
|
||
var throttleCount = 0, | ||
throttleAmount = 1000; | ||
|
||
/** | ||
* Update the server's stored settings. | ||
* Calls to this function are throttled. | ||
* @param keyChanged - they key of the property that just changed | ||
* @param object - the preferences object that will be sent back to the server | ||
*/ | ||
methods.updatePreferences = function throttleWrapper(object) { | ||
console.debug("updatePreferences: throttled", object); | ||
throttleCount++; | ||
|
||
return _.throttle( | ||
function updatePreferences(object) { | ||
console.debug("updatePreferences: sending to server, waited %s attempts", throttleCount); | ||
throttleCount = 0; | ||
|
||
$http.put(preferencesUrl).then( | ||
function success(response) { | ||
console.info("updatePreferences:success"); | ||
}, | ||
function error(response) { | ||
console.error("updatePreferences:failed", response); | ||
} | ||
); | ||
}, throttleAmount); | ||
}; | ||
|
||
methods.get = function (scope, property) { | ||
scope[property] = {preferences: null}; | ||
|
||
$http.get(profileUrl).then( | ||
function success(response) { | ||
console.log("User profile loaded"); | ||
|
||
scope[property] = (new baw.UserProfile(methods, response.data, constants.defaultProfile)); | ||
}, | ||
function error(response) { | ||
console.error("User profile load failed", response); | ||
|
||
scope[property] = (new baw.UserProfile(methods, null, constants.defaultProfile)); | ||
} | ||
).finally(function () { | ||
scope.$watch(function () { | ||
return scope[property].preferences; | ||
}, function (newValue, oldValue) { | ||
if (newValue == oldValue) { | ||
return; | ||
} | ||
|
||
methods.updatePreferences(newValue); | ||
}, true); | ||
}); | ||
}; | ||
|
||
|
||
return methods; | ||
} | ||
]); |
This file was deleted.
Oops, something went wrong.