Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
feat(userManager): selected users can now be exported between sets
Browse files Browse the repository at this point in the history
closes #46
  • Loading branch information
seiyria committed Oct 16, 2015
1 parent 2e9c0c9 commit 74f0a3c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/jade/partials/dialogs/select-prompt.jade
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ script(type="text/ng-template", id="/dialog/select-prompt")
label {{label}}
md-select(ng-model="string", required)
md-optgroup(ng-repeat="group in groups", label="{{group}}")
md-option(ng-repeat="value in selectableValues | filter:{group:group}") {{value.realName}}
md-option(ng-repeat="value in selectableValues | filter:{group:group}", value="{{value}}") {{value.realName}}

.md-actions
md-button.md-primary(ng-click="submit()", ng-disabled="form.$invalid", aria-label="submit") Submit
Expand Down
4 changes: 2 additions & 2 deletions src/jade/partials/managers/user-manage.jade
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ script(type="text/ng-template", id="/user-manage")
ng-md-icon(size="24", icon="edit", style="fill: white")
md-tooltip(md-direction="left") Rename current player set

md-button.md-fab.md-raised.md-accent.md-hue-1(aria-label="export to set", ng-if="false")
ng-md-icon(size="24", icon="input", style="fill: white")
md-button.md-fab.md-raised.md-accent.md-hue-1(aria-label="export to set", ng-click="doExport($event)", ng-if="selected.length > 0 && hasMultipleSets()")
ng-md-icon(size="24", icon="recent_actors", style="fill: white")
md-tooltip(md-direction="left") Export to another player set

md-button.md-fab.md-raised.md-warn.md-hue-1(aria-label="share set", ng-click="openShareDialog($event)", ng-if="ownsCurrentSet()")
Expand Down
16 changes: 15 additions & 1 deletion src/js/controllers/managers/userManageCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,23 @@ site.controller('userManageController', ($scope, $firebaseArray, $firebaseObject

$scope.doOrOpen = (event) => $scope.isOpen ? $scope.doChange(event) : $scope.isOpen = true;

$scope.doExport = (event) => SetManagement.exportSet(event, _.reject($scope.listKeys, k => k.short === $scope.setObject.basename), $scope.exportToSet);

$scope.openShareDialog = (event) => SetManagement.shareSet(event, $scope.setObject.realName, $scope.setObject.sharedWith, $scope.updateShareSettings);

$scope.changeSetFromRealname = (newSet) => $scope.changePlayerSet(_.findWhere($scope.listKeys, { realName: newSet }).short);
$scope.changeSetFromRealname = (newSet) => $scope.changePlayerSet(_.findWhere($scope.listKeys, { realName: newSet.short }).short);

$scope.exportToSet = (newSet) => {
const players = $scope.selected;

const newSetPlayers = $firebaseArray(new Firebase(`${FirebaseURL}/users/${newSet.uid}/players/${newSet.short}/list`));

const newPlayerObjs = _.map(players, p => _.omit(p, (v, key) => _.contains(key, '$') || _.contains(['wins', 'losses', 'points'], key)));

newSetPlayers.$loaded(() => {
_.each(newPlayerObjs, newSetPlayers.$add);
});
};

$scope.updateShareSettings = (shareData) => {
const oldSharedWith = _.keys($scope.setObject.shareIDs);
Expand Down
20 changes: 17 additions & 3 deletions src/js/services/managers/setManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ site.service('SetManagement', (FirebaseURL, $mdDialog, InputPrompt, SelectPrompt
title: 'Choose a player set',
label: 'Player set'
}, (string) => {
Toaster.show(`Successfully changed player set to "${string}"`);
callback(string);
const val = JSON.parse(string);
Toaster.show(`Successfully changed player set to "${val.realName}"`);
callback(val);
});
};

const exportSet = (event, choices, callback) => {
SelectPrompt.show(event, {
selectableValues: choices,
title: 'Choose a player set',
label: 'Player set'
}, (string) => {
const val = JSON.parse(string);
Toaster.show(`Successfully exported to player set "${val.realName}"`);
callback(val);
});
};

Expand Down Expand Up @@ -65,6 +78,7 @@ site.service('SetManagement', (FirebaseURL, $mdDialog, InputPrompt, SelectPrompt
renameSet,
deleteSet,
shareSet,
changeSet
changeSet,
exportSet
};
});

0 comments on commit 74f0a3c

Please sign in to comment.