Skip to content

Commit

Permalink
Merge pull request #859 from eciis/fix-reload-shared-survey-post
Browse files Browse the repository at this point in the history
Fix shared survey post when reload the post
  • Loading branch information
mayzabeel authored Mar 2, 2018
2 parents 087b486 + 4eb37ea commit 9a9f9cd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
5 changes: 5 additions & 0 deletions frontend/post/postDetailsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
!postDetailsCtrl.isDeleted(postDetailsCtrl.post);
};

postDetailsCtrl.showSharedPostText = function showSharedPostText() {
return !postDetailsCtrl.isDeleted(postDetailsCtrl.post.shared_post) &&
!postDetailsCtrl.post.shared_post.type_survey;
};

postDetailsCtrl.showSharedEvent = function showSharedEvent() {
return postDetailsCtrl.post.shared_event &&
!postDetailsCtrl.isDeleted(postDetailsCtrl.post) &&
Expand Down
17 changes: 10 additions & 7 deletions frontend/post/post_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<span>por {{postDetailsCtrl.post.last_modified_by}} {{postDetailsCtrl.post.last_modified_date | amUtc | amLocal | amCalendar:referenceTime:formats }}.</span>
</div>
</div>
<md-card-content layout="column">
<md-card-content layout="column" ng-class="postDetailsCtrl.post.shared_post.type_survey ? 'shared-survey' : ''">
<img class="md-card-image" ng-if="postDetailsCtrl.showImage(postDetailsCtrl.post.shared_post)"
style="width: 100%; height: auto;" ng-src="{{ postDetailsCtrl.post.shared_post.photo_url }}"/>
<div class="youtube-player" ng-if="postDetailsCtrl.showVideo(postDetailsCtrl.post.shared_post)">
Expand All @@ -129,16 +129,19 @@
href class="md-text hyperlink" ng-click="postDetailsCtrl.goToPost(postDetailsCtrl.post.shared_post)">
<span>{{ postDetailsCtrl.post.shared_post.title }}</span>
</a>
<p class="text" ng-if="!postDetailsCtrl.isDeleted(postDetailsCtrl.post.shared_post)"
<p class="text" ng-if="postDetailsCtrl.showSharedPostText()"
ng-bind-html="postDetailsCtrl.postToURL(postDetailsCtrl.post.shared_post).text" ></p>
<div layout="row" layout-align="end-center">
<a href class="md-text hyperlink" ng-click="postDetailsCtrl.goToPost(postDetailsCtrl.post.shared_post)"
ng-if="postDetailsCtrl.isLongPostTimeline(postDetailsCtrl.post.shared_post.text)">
<div layout="row" layout-align="end-center"
ng-if="postDetailsCtrl.isLongPostTimeline(postDetailsCtrl.post.shared_post.text)">
<a href class="md-text hyperlink"
ng-click="postDetailsCtrl.goToPost(postDetailsCtrl.post.shared_post)">
<md-icon>more_horiz</md-icon>
</a>
</div>
<pdf-view pdf-files='postDetailsCtrl.post.shared_post.pdf_files' is-editing="false"></pdf-view>
<survey-details ng-if="postDetailsCtrl.post.shared_post.type_survey" post="postDetailsCtrl.post.shared_post" posts="postDetailsCtrl.posts" user="postDetailsCtrl.user" isdialog="false"></survey-details>
<pdf-view ng-if="postDetailsCtrl.showSharedPostText()" pdf-files='postDetailsCtrl.post.shared_post.pdf_files' is-editing="false"></pdf-view>
<survey-details ng-if="postDetailsCtrl.post.shared_post.type_survey"
post="postDetailsCtrl.post.shared_post" posts="postDetailsCtrl.posts"
user="postDetailsCtrl.user" isdialog="false"></survey-details>
</md-card-content>
</md-card>

Expand Down
5 changes: 5 additions & 0 deletions frontend/styles/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -968,3 +968,8 @@ md-input-container:not(.md-input-invalid).md-input-has-value .inputEmail {
text-align: center;
font-size: 15px;
}

.shared-survey{
padding-top :0px;
margin-top : -25px;
}
20 changes: 10 additions & 10 deletions frontend/survey/surveyDetailsDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
surveyCtrl.userVoted = function(){
var voted = false;
_.forEach(surveyCtrl.post.options, function(option) {
if(surveyCtrl.votedOption(option)) {voted = true;}
(surveyCtrl.votedOption(option)) ? voted = true : null;
});
return voted;
};
Expand Down Expand Up @@ -95,7 +95,6 @@
var promise = SurveyService.vote(surveyCtrl.post, surveyCtrl.optionsSelected);
promise.then(function sucess(){
addVote(surveyCtrl.optionsSelected);
calculatePercentage();
MessageService.showToast('Voto computado');
});
return promise;
Expand Down Expand Up @@ -124,20 +123,22 @@
_.forEach(options, function(option) {
surveyCtrl.post.number_votes += 1;
option.number_votes += 1;
calculatePercentage(option);
var voter = {'name': surveyCtrl.user.name,
'photo_url': surveyCtrl.user.photo_url,
'key': Utils.getKeyFromUrl(surveyCtrl.user.key) };
option.voters.push(voter);
});
}

function calculatePercentage(){
if(surveyCtrl.post){
_.forEach(surveyCtrl.post.options, function(option) {
var percentage = (option.number_votes / surveyCtrl.post.number_votes) * 100;
option.percentage = surveyCtrl.post.number_votes === 0 ? 0 : percentage.toFixed(0);
});
}
function calculatePercentage(option){
option.percentage = (surveyCtrl.post.number_votes === 0) ? 0 :
((option.number_votes / surveyCtrl.post.number_votes) * 100).toFixed(0);
}

surveyCtrl.getPercentage = function getPercentage(option){
(!option.percentage) ? calculatePercentage(option) : null;
return option.percentage + "%";
}

surveyCtrl.scrollbarConfig = {
Expand All @@ -148,7 +149,6 @@

surveyCtrl.loadAttributes = function(){
loadBinarySelected();
calculatePercentage();
};

surveyCtrl.showMenu = function(ev, option) {
Expand Down
5 changes: 3 additions & 2 deletions frontend/survey/survey_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
ng-if="surveyCtrl.showCheckboxButton()" ng-model="option.selected"></md-checkbox>
<p ng-if="!surveyCtrl.isPostPage">{{surveyCtrl.getOption(option.text)}}</p>
<p ng-if="surveyCtrl.isPostPage">{{option.text}}</p>
<div ng-if="surveyCtrl.userVoted() || surveyCtrl.isSurveyAuthor() || surveyCtrl.timeHasBeenExpired()" ng-click="surveyCtrl.showMenu($event, option)" title="Clique para ver quem votou nessa opção">
<div ng-if="surveyCtrl.userVoted() || surveyCtrl.isSurveyAuthor() || surveyCtrl.timeHasBeenExpired()"
ng-click="surveyCtrl.showMenu($event, option)" title="Clique para ver quem votou nessa opção">
<div ng-class="surveyCtrl.votedOption(option)?'percentage-selected':'option-percentage'">
{{option.percentage ? option.percentage : 0}}%
{{surveyCtrl.getPercentage(option)}}
</div>
</div>
</md-list-item>
Expand Down

0 comments on commit 9a9f9cd

Please sign in to comment.