Skip to content

Commit

Permalink
fix(userTile): Made userTile more robust
Browse files Browse the repository at this point in the history
It used to show partial templating even if a user model could not be
resolved. It will now hide compeltely unless a user model is resolved -
looks much cleaner.
  • Loading branch information
atruskie committed Dec 1, 2016
1 parent a02305e commit 10b15f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/app/users/userTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,37 @@ angular
.controller("UserTileController", [
"$scope", "moment", "conf.paths", "UserProfile",
function ($scope, moment, paths, UserProfile) {
var self = this;
var $ctrl = this;
let userKey, dateKey;

this.defaultUserImage = paths.site.assets.users.defaultImageAbsolute;
this.userProfile = null;
this.friendlyDate = null;
this.show = false;

$scope.$watch(
(scope) => scope.$ctrl.resource,
function () {
if (!self.resource) {
if (!$ctrl.resource) {
$ctrl.show = false;
return;
}

if(!$ctrl.resource[userKey] || $ctrl.resource[dateKey]) {
$ctrl.show = false;
return;
}

// update the user profile
UserProfile
.getUserForMetadataTile(self.resource[userKey])
.getUserForMetadataTile($ctrl.resource[userKey])
.then((result) => {
self.userProfile = result.data.data[0];
$ctrl.userProfile = result.data.data[0];
$ctrl.show = true;
});

// update the friendly date
self.friendlyDate = moment(self.resource[dateKey]).fromNow();
$ctrl.friendlyDate = moment($ctrl.resource[dateKey]).fromNow();
});

this.$onInit = function () {
Expand Down
4 changes: 2 additions & 2 deletions src/app/users/userTile.tpl.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ng-transclude ng-show="$ctrl.resource"></ng-transclude>
<div class="media" ng-show="$ctrl.resource" ng-class="{skinny: $ctrl.skinny !== undefined}">
<ng-transclude ng-show="$ctrl.show"></ng-transclude>
<div class="media" ng-show="$ctrl.show" ng-class="{skinny: $ctrl.skinny !== undefined}">
<div class="media-left media-middle">
<a ng-href="{{ $ctrl.userProfile.url }}">
<img alt="{{ $ctrl.userProfile.userName }}"
Expand Down

0 comments on commit 10b15f0

Please sign in to comment.