Skip to content

Commit

Permalink
clear questions functionality for admin
Browse files Browse the repository at this point in the history
  • Loading branch information
arhill05 committed Sep 6, 2017
1 parent 162dcb7 commit 17454ba
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
15 changes: 15 additions & 0 deletions app/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,21 @@ body .hidden {
padding: 16px;
margin: 8px;
}
body #content #questions .questions-content .session-info .clear-questions-button {
margin: 0 8px;
cursor: pointer;
background-color: #ff8c00;
color: #FBFFFE;
border: none;
padding: 8px;
border-radius: 2px;
border-right: 3px solid #cc7000;
border-bottom: 3px solid #cc7000;
float: right;
}
body #content #questions .questions-content .session-info .clear-questions-button:active {
background-color: #cc7000;
}
body #content #questions .questions-content .session-info .session-title {
font-size: 240%;
font-weight: 700;
Expand Down
39 changes: 26 additions & 13 deletions app/js/controllers/session.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ app.controller('sessionCtrl', [

Auth.$onAuthStateChanged(function (firebaseUser) {
$scope.auth = firebaseUser;
let usersRef = firebase
.database()
.ref()
.child("users/" + $scope.auth.uid);
let userObj = $firebaseObject(usersRef);
userObj
.$bindTo($scope, "user")
.then(function () {
console.log($scope.user);
});
if ($scope.auth) {
let usersRef = firebase
.database()
.ref()
.child("users/" + $scope.auth.uid);
let userObj = $firebaseObject(usersRef);
userObj
.$bindTo($scope, "user")
.then(function () {
console.log($scope.user);
});
}
});

}

self.upvoteQuestion = function (question) {
Expand Down Expand Up @@ -121,10 +124,10 @@ app.controller('sessionCtrl', [
self.userIsAdmin = () => {
if ($scope.session && $scope.user && $scope.user.$id == $scope.session.sessionOwnerUID) {
return true;
} else
} else
return false;
}
}

self.onHomeClick = () => {
$state.go('start');
}
Expand All @@ -141,6 +144,16 @@ app.controller('sessionCtrl', [
return ($scope.user && $scope.user.upvotedQuestionIds && $scope.user.upvotedQuestionIds.indexOf(question.$id) > -1)
}

self.clearQuestions = () => {
let questionsRef = firebase
.database()
.ref()
.child('sessions_questions')
.child($scope.session.$id);

questionsRef.remove();
}

self.onInit();
}
]);
4 changes: 4 additions & 0 deletions app/less/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,10 @@ body {
box-shadow: @float-box-shadow;
padding: @double-space;
margin: @single-space;
.clear-questions-button {
.primary-button;
float: right;
}
.session-title {
font-size: 240%;
font-weight: 700;
Expand Down
1 change: 1 addition & 0 deletions app/views/session.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div class="loading" ng-if="showLoading">LOADING . . . </div>
<div class="questions-content">
<div id="action-buttons" class="action-buttons">
<button ng-if="$ctrl.userIsAdmin()" ng-click="$ctrl.clearQuestions()">Clear Questions</button>
<button ng-click="$ctrl.onHomeClick()">Home</button>
<button ng-if="!user || user.anonymous" ng-click="$ctrl.onLoginClick()" class="login-button">Login</button>
<button ng-if="user && !user.anonymous" ng-click="$ctrl.onAccountClick()" class="login-button">Account</button>
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"angular-ui-router": "ui-router#^0.4.2",
"angularfire": "^2.3.0",
"toastr": "^2.1.3",
"firebase": "^3.7.4"
"firebase": "^3.7.4",
"angular-animate": "^1.6.6"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"gulp-html-replace": "^1.6.2",
"gulp-jshint": "^2.0.4",
"gulp-less": "^3.3.0",
"gulp-minify": "^1.0.0",
"gulp-sftp": "^0.1.5",
"gulp-uglify": "^2.1.2",
"gulp-util": "^3.0.8",
Expand Down

0 comments on commit 17454ba

Please sign in to comment.