Skip to content
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

[WIP] Fix #1705 :Adds support for editing the challenge start and end date #2144

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion bower.json
Expand Up @@ -31,7 +31,8 @@
"angular-trix": "^1.0.2",
"angular-moment": "^1.2.0",
"moment": "^2.21.0",
"ngclipboard": "^2.0.0"
"ngclipboard": "^2.0.0",
"moment-picker": "0.10.2"
},
"resolutions": {
"angular": "1.7.0"
Expand Down
6 changes: 4 additions & 2 deletions frontend/app.scripts.json
Expand Up @@ -21,7 +21,8 @@
"locale",
"angular-moment",
"clipboard",
"ngclipboard"
"ngclipboard",
"moment-picker"
]
},
"paths": {
Expand All @@ -45,7 +46,8 @@
"locale": "bower_components/moment/locale/de.js",
"angular-moment": "bower_components/angular-moment/angular-moment.js",
"clipboard": "bower_components/clipboard/dist/clipboard.min.js",
"ngclipboard": "bower_components/ngclipboard/dist/ngclipboard.min.js"
"ngclipboard": "bower_components/ngclipboard/dist/ngclipboard.min.js",
"moment-picker": "bower_components/angular-moment-picker/dist/angular-moment-picker.js"

}
}
6 changes: 4 additions & 2 deletions frontend/app.styles.json
Expand Up @@ -5,14 +5,16 @@
"angular-material",
"materialize",
"AngularJS-Toaster",
"trix"
"trix",
"moment-picker"
]
},
"paths": {
"animate": "bower_components/animate.css/animate.css",
"angular-material": "bower_components/angular-material/angular-material.css",
"materialize": "bower_components/materialize/dist/css/materialize.css",
"AngularJS-Toaster": "bower_components/AngularJS-Toaster/toaster.min.css",
"trix": "bower_components/trix/dist/trix.css"
"trix": "bower_components/trix/dist/trix.css",
"moment-picker": "bower_components/angular-moment-picker/dist/angular-moment-picker.css"
}
}
3 changes: 2 additions & 1 deletion frontend/src/js/app.js
Expand Up @@ -13,7 +13,8 @@ angular
'toaster',
'angularTrix',
'angularMoment',
'ngclipboard'
'ngclipboard',
'moment-picker'
]).config(['$compileProvider', function($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|file|tel|javascript):/);
}]);
65 changes: 65 additions & 0 deletions frontend/src/js/controllers/challengeCtrl.js
Expand Up @@ -39,6 +39,7 @@
vm.columnIndexSort = 0;
// save initial ranking
vm.initial_ranking = {};
vm.status = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of this variable? Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RishabhJain2018 I am using this variable in ng-if to render edit startdate/enddate form.


// loader for existing teams
vm.isExistLoader = false;
Expand Down Expand Up @@ -1526,6 +1527,70 @@
}
};

// Edit Challenge Date
vm.challengeDateDialog = function(ev) {
vm.tempChallengeStart = vm.page.start_date;
vm.tempChallengeEnd = vm.page.end_date;
$mdDialog.show({
scope: $scope,
preserveScope: true,
targetEvent: ev,
templateUrl: 'dist/views/web/challenge/edit-challenge/edit-challenge-date.html',
escapeToClose: false
});
};

vm.editChallengeDate = function(editChallengeDateForm) {
if (editChallengeDateForm) {
var challengeHostList = utilities.getData("challengeCreator");
for (var challenge in challengeHostList) {
if (challenge == vm.challengeId) {
vm.challengeHostId = challengeHostList[challenge];
break;
}
}
parameters.url = "challenges/challenge_host_team/" + vm.challengeHostId + "/challenge/" + vm.challengeId;
parameters.method = 'PATCH';
var start = new Date(vm.page.start_date).valueOf()
var end = new Date(vm.page.end_date).valueOf()
if (start < end){
parameters.data = {
"start_date": vm.page.start_date,
"end_date": vm.page.end_date
};
parameters.callback = {
onSuccess: function(response) {
var status = response.status;
if (status === 200) {
$mdDialog.hide();
if (vm.status == 'Start'){
$rootScope.notify("success", "The challenge start date is updated!");
}
if (vm.status === 'End'){
$rootScope.notify("success", "The challenge end date is updated!");
}

}
},
onError: function(response) {
$mdDialog.hide();
vm.page.start_date = vm.tempChallengeStart;
vm.page.end_date = vm.tempChallengeEnd;
var error = response.data;
$rootScope.notify("error", error);
}
};
}else{
$rootScope.notify("error", "The challenge start date is greater than end date");
}
utilities.sendRequest(parameters);
} else {
vm.page.start_date = vm.tempChallengeStart;
vm.page.end_date = vm.tempChallengeEnd;
$mdDialog.hide();
}
};

vm.challengePhaseDialog = function(ev, phase) {
vm.page.challenge_phase = phase;
vm.phaseStartDate = new Date(phase.start_date);
Expand Down
17 changes: 17 additions & 0 deletions frontend/src/views/web/challenge/challenge-page.html
Expand Up @@ -34,6 +34,23 @@
<strong class="text-light-black">Published </strong>
<i class="fa fa-eye green-text" aria-hidden="true"></i>
</a>
<br>
<span> <strong class="text-light-black">Started On: </strong>
<span>{{challenge.page.start_date | date:'medium'}}</span>

</span>
<a class="pointer" ng-click="challenge.challengeDateDialog($event);challenge.status='Start'">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
<br>
<span>
<strong class="text-light-black">Ends
On: </strong>
<span>{{challenge.page.end_date | date:'medium'}}</span>
</span>
<a class="pointer" ng-click="challenge.challengeDateDialog($event);challenge.status='End'">
<i class="fa fa-pencil" aria-hidden="true"></i>
</a>
</span>
<span ng-if="!challenge.isPublished">
<a class="pointer" ng-click="challenge.publishChallenge($event)">
Expand Down
@@ -0,0 +1,38 @@
<section class="ev-md-container text-center rm-overflow-y">
<div class="row">
<div class="col s12 m12">
<div class="ev-card-body pd-20 font-size-16">
<form name="editChallengeDateForm" ng-submit="challenge.editChallengeDate(editChallengeDateForm.$valid)">
<div class="pass-date" ng-if = "challenge.status == 'Start'">Edit challenge start date</div>
<div class="pass-date" ng-if = "challenge.status == 'End'">Edit challenge end date</div>
<div class="input-field align-left">
<input
ng-if = "challenge.status == 'Start'"
focus-if="challenge.page.start_date"
value="{{challenge.page.start_date}}"
ng-model="challenge.page.start_date"
ng-model-options="{ updateOn: 'blur' }"
moment-picker="ctrl.input"
placeholder="Start Date">
<input
ng-if = "challenge.status == 'End'"
focus-if="challenge.page.end_date"
value="{{challenge.page.end_date}}"
ng-model="challenge.page.end_date"
ng-model-options="{ updateOn: 'blur' }"
moment-picker="ctrl.input"
placeholder="End Date">
</div>
<ul class="inline-list pointer">
<li>
<a ng-click="challenge.editChallengeDate(false)" class="dark-link pointer"><strong>Cancel</strong></a>
</li>
<li>
<button class="btn ev-btn-dark waves-effect waves-dark grad-btn grad-btn-dark fs-14" ng-disabled="editChallengeDateForm.$pristine" type="submit" value="submit">Submit</button>
</li>
</ul>
</form>
</div>
</div>
</div>
</section>
4 changes: 4 additions & 0 deletions frontend/src/views/web/hosted-challenges.html
Expand Up @@ -16,9 +16,13 @@
<p><strong class="text-light-black fs-12">Organized by</strong>
<strong>{{challenge.creator.team_name}}</strong></p>
<p><strong class="text-light-black fs-12">Starts on</strong>
<div ng-click="">
<br> <strong>{{challenge.start_date | date:'medium'}}</strong></p>
</div>
<p><strong class="text-light-black fs-12">Ends on</strong>
<div>
<br> <strong>{{challenge.end_date | date:'medium'}}</strong></p>
</div>
<div class="margin-top-btm">
<span ng-if="challenge.approved_by_admin">
<div class="chip green white-text">Approved</div>
Expand Down