Skip to content

Commit

Permalink
Add CapitalizeService and AuthService
Browse files Browse the repository at this point in the history
These servies will allow you to get the login status of a user. This also shows how to share state across components.
  • Loading branch information
little9 committed Feb 15, 2024
1 parent 342f017 commit d621197
Showing 1 changed file with 48 additions and 9 deletions.
57 changes: 48 additions & 9 deletions 01JHU_INST-JHU/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

var app = angular.module('viewCustom', ['angularLoad']);

const capitalize = (string) => {
if (!string) return string;
return string.charAt(0).toUpperCase() + string.slice(1);
}
/* Components */

app.component('prmTopBarBefore', {
bindings: { parentCtrl: `<` },
Expand Down Expand Up @@ -34,17 +31,30 @@
app.component('prmLocationAfter', {
bindings: { parentCtrl: '<' },
templateUrl: "/discovery/custom/01JHU_INST-JHU/html/prm-location-after.html",
controller: function ($scope) {
$scope.capitalize = capitalize;
controller: ['AuthService', 'CapitalizeService', function (AuthService, CapitalizeService) {
this.capitalize = CapitalizeService.capitalize;
this.isLoggedIn = AuthService.getIsLoggedIn();

this.$onInit = function () {
console.log("prmLocationsAfter")
};
}
console.log(this.isLoggedIn);
}
}]
});

/* Used to get the user's authentication information -- not displayed */
app.component('prmAuthenticationAfter', {
bindings: { parentCtrl: '<' },
template: '<div></div>',
controller: ['AuthService', function (AuthService) {

this.$onInit = function () {
AuthService.setIsLoggedIn(this.parentCtrl.isLoggedIn);
}
}]
});

/* This is an override of the prmLocationItems component. prmLocationItems displays the items at a location. */
/* This is component is more complex that prmLocation. */
app.component('prmLocationItemsAfter', {
bindings: { parentCtrl: '<' },
templateUrl: "/discovery/custom/01JHU_INST-JHU/html/prm-location-items-after.html",
Expand All @@ -56,5 +66,34 @@
};
}
});


/*Services */

/* Simple service used to capitalize the first letter of a string */
app.service('CapitalizeService', function() {
this.capitalize = function(string) {
if (!string) return string;
return string.charAt(0).toUpperCase() + string.slice(1);
}
});

/* This service is used to keep track of whether the user is logged in or not. */
app.service('AuthService', function() {
var isLoggedIn = false;

return {
setIsLoggedIn: function(value) {
if (value === false) {
isLoggedIn = false;
} else {
isLoggedIn = true;
}
},
getIsLoggedIn: function() {
return isLoggedIn;
}
};
});

})();

0 comments on commit d621197

Please sign in to comment.