Skip to content

This fixes issue 28 #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
angular.module("umbraco").controller("Analytics.SettingsController",
function ($scope, $routeParams, settingsResource, notificationsService, localizationService, navigationService) {
function ($scope, $timeout, $routeParams, analyticsSettingsResource, notificationsService, localizationService, navigationService) {

//By default user has not authorised
var hasUserAuthd = false;

//Get all settings via settingsResource - does WebAPI GET call
settingsResource.getall().then(function (response) {
//Get all settings via analyticsSettingsResource - does WebAPI GET call
analyticsSettingsResource.getall().then(function (response) {
$scope.settings = response.data;
});

//Get Account JSON & bind back to dropdown
settingsResource.getaccount().then(function (response) {
analyticsSettingsResource.getaccount().then(function (response) {
if (response.data === "null") {
$scope.selectedaccount = null;
}
Expand All @@ -20,7 +20,7 @@
});

//Get Profile JSON & bind back to dropdown
settingsResource.getprofile().then(function (response) {
analyticsSettingsResource.getprofile().then(function (response) {
if (response.data === "null") {
$scope.selectedprofile = null;
}
Expand All @@ -31,27 +31,29 @@


//Get oAuth Check - WebAPI GET (Basically checks if RefreshToken has a value)
settingsResource.checkauth().then(function (response) {
analyticsSettingsResource.checkauth().then(function (response) {

//Show or hide the auth button (set on scope & local var for if check)
hasUserAuthd = response.data === "true";

//Apply
$scope.$apply(function () {
$timeout(function(){
// any code in here will automatically have an apply run afterwards
// source: https://stackoverflow.com/a/23102223
$scope.hasAuthd = hasUserAuthd;
});

//Only load/fetch if showAuth is true
if (hasUserAuthd === true) {

//Get all accounts via settingsResource - does WebAPI GET call
settingsResource.getaccounts().then(function (response) {
//Get all accounts via analyticsSettingsResource - does WebAPI GET call
analyticsSettingsResource.getaccounts().then(function (response) {
$scope.accounts = response.data;

if ($scope.selectedaccount != null) {
$scope.selectedaccount = _.where($scope.accounts, { Id: $scope.selectedaccount.Id })[0];

settingsResource.getprofiles($scope.selectedaccount.Id).then(function (response) {
analyticsSettingsResource.getprofiles($scope.selectedaccount.Id).then(function (response) {
$scope.profiles = response.data;
if ($scope.selectedprofile != null) {
$scope.selectedprofile = _.where($scope.profiles, { Id: $scope.selectedprofile.Id })[0];
Expand All @@ -63,7 +65,7 @@

//When an account is selected
$scope.accountSelected = function (selectedAccount) {
settingsResource.getprofiles(selectedAccount.Id).then(function (response) {
analyticsSettingsResource.getprofiles(selectedAccount.Id).then(function (response) {
$scope.profiles = response.data;
});
};
Expand All @@ -83,23 +85,23 @@
$scope.save = function (settings, account, profile) {

//Save settings resource - does a WebAPI POST call
settingsResource.save(settings).then(function (response) {
analyticsSettingsResource.save(settings).then(function (response) {
$scope.settings = response.data;

//Display Success message
notificationsService.success(localizationService.localize("analytics_settingsSaved"));
});

//Save settings resource - does a WebAPI POST call
settingsResource.saveAccount(account).then(function (response) {
analyticsSettingsResource.saveAccount(account).then(function (response) {
//Don't need anything from response.data back

//Display Success message
notificationsService.success(localizationService.localize("analytics_accountDetailsSaved"));
});

//Save settings resource - does a WebAPI POST call
settingsResource.saveProfile(profile).then(function (response) {
analyticsSettingsResource.saveProfile(profile).then(function (response) {
//Don't need anything from response.data back

//Display Success message
Expand All @@ -111,5 +113,9 @@

};

navigationService.syncTree({ tree: 'analyticsTree', path: ["-1", $routeParams.id], forceReload: false });
$timeout(function(){
// any code in here will automatically have an apply run afterwards
// source: https://stackoverflow.com/a/23102223
navigationService.syncTree({ tree: 'analyticsTree', path: ["-1", $routeParams.id], forceReload: false });
});
});