Reworks the banner showing if there are polls
- Makes it higher on mobilephones - Changes title, if there is only one poll
This commit is contained in:
parent
b16afaa285
commit
c46369c6a7
@ -10,6 +10,7 @@ export interface BannerDefinition {
|
|||||||
bgColor?: string;
|
bgColor?: string;
|
||||||
color?: string;
|
color?: string;
|
||||||
link?: string;
|
link?: string;
|
||||||
|
largerOnMobileView?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,8 +21,6 @@ export interface BannerDefinition {
|
|||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class BannerService {
|
export class BannerService {
|
||||||
public readonly BANNER_HEIGHT = 20;
|
|
||||||
|
|
||||||
public activeBanners: BehaviorSubject<BannerDefinition[]> = new BehaviorSubject<BannerDefinition[]>([]);
|
public activeBanners: BehaviorSubject<BannerDefinition[]> = new BehaviorSubject<BannerDefinition[]>([]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
|||||||
|
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|
||||||
|
import { ViewMotionPoll } from 'app/site/motions/models/view-motion-poll';
|
||||||
import { ViewBasePoll } from 'app/site/polls/models/view-base-poll';
|
import { ViewBasePoll } from 'app/site/polls/models/view-base-poll';
|
||||||
import { PollListObservableService } from 'app/site/polls/services/poll-list-observable.service';
|
import { PollListObservableService } from 'app/site/polls/services/poll-list-observable.service';
|
||||||
import { BannerDefinition, BannerService } from './banner.service';
|
import { BannerDefinition, BannerService } from './banner.service';
|
||||||
@ -29,37 +30,66 @@ export class VotingBannerService {
|
|||||||
* @param polls the updated poll list
|
* @param polls the updated poll list
|
||||||
*/
|
*/
|
||||||
private checkForVotablePolls(polls: ViewBasePoll[]): void {
|
private checkForVotablePolls(polls: ViewBasePoll[]): void {
|
||||||
// display no banner if in history mode
|
// display no banner if in history mode or there are no polls to vote
|
||||||
if (this.OSStatus.isInHistoryMode && this.currentBanner) {
|
const pollsToVote = polls.filter(poll => this.votingService.canVote(poll) && !poll.user_has_voted);
|
||||||
this.banner.removeBanner(this.currentBanner);
|
if ((this.OSStatus.isInHistoryMode && this.currentBanner) || !pollsToVote.length) {
|
||||||
this.currentBanner = null;
|
this.sliceBanner();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pollsToVote = polls.filter(poll => this.votingService.canVote(poll) && !poll.user_has_voted);
|
const banner =
|
||||||
if (pollsToVote.length === 1) {
|
pollsToVote.length === 1
|
||||||
const poll = pollsToVote[0];
|
? this.createBanner(this.getTextForPoll(pollsToVote[0]), pollsToVote[0].parentLink)
|
||||||
const banner = {
|
: this.createBanner(
|
||||||
text: this.translate.instant('Click here to vote on the poll') + ` "${poll.title}"!`,
|
`${this.translate.instant('You have polls to vote on')}: ${pollsToVote.length}`,
|
||||||
link: poll.parentLink,
|
'/polls/'
|
||||||
bgColor: 'green'
|
);
|
||||||
};
|
this.sliceBanner(banner);
|
||||||
this.banner.replaceBanner(this.currentBanner, banner);
|
}
|
||||||
this.currentBanner = banner;
|
|
||||||
} else if (pollsToVote.length > 1) {
|
/**
|
||||||
const banner = {
|
* Creates a new `BannerDefinition` and returns it.
|
||||||
text:
|
*
|
||||||
this.translate.instant('You have') +
|
* @param text The text for the banner.
|
||||||
` ${pollsToVote.length} ` +
|
* @param link The link for the banner.
|
||||||
this.translate.instant('polls to vote on!'),
|
*
|
||||||
link: '/polls/',
|
* @returns The created banner.
|
||||||
bgColor: 'green'
|
*/
|
||||||
};
|
private createBanner(text: string, link: string): BannerDefinition {
|
||||||
this.banner.replaceBanner(this.currentBanner, banner);
|
return {
|
||||||
this.currentBanner = banner;
|
text: text,
|
||||||
|
link: link,
|
||||||
|
icon: 'how_to_vote',
|
||||||
|
largerOnMobileView: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns for a given poll a title for the banner.
|
||||||
|
*
|
||||||
|
* @param poll The given poll.
|
||||||
|
*
|
||||||
|
* @returns The title.
|
||||||
|
*/
|
||||||
|
private getTextForPoll(poll: ViewBasePoll): string {
|
||||||
|
return poll instanceof ViewMotionPoll
|
||||||
|
? `${this.translate.instant('Motion') + ' ' + poll.motion.getIdentifierOrTitle()}: ${this.translate.instant(
|
||||||
|
'Voting started'
|
||||||
|
)}!`
|
||||||
|
: `${poll.getTitle()}: ${this.translate.instant('Ballots opened')}!`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the current banner or replaces it, if a new one is given.
|
||||||
|
*
|
||||||
|
* @param nextBanner Optional the next banner to show.
|
||||||
|
*/
|
||||||
|
private sliceBanner(nextBanner?: BannerDefinition): void {
|
||||||
|
if (nextBanner) {
|
||||||
|
this.banner.replaceBanner(this.currentBanner, nextBanner);
|
||||||
} else {
|
} else {
|
||||||
this.banner.removeBanner(this.currentBanner);
|
this.banner.removeBanner(this.currentBanner);
|
||||||
this.currentBanner = null;
|
|
||||||
}
|
}
|
||||||
|
this.currentBanner = nextBanner || null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
<div
|
<div
|
||||||
*ngFor="let banner of banners"
|
*ngFor="let banner of banners"
|
||||||
class="banner"
|
class="banner"
|
||||||
[ngClass]="(banner.type === 'history' ? 'history-mode-indicator' : '') + ' ' + (banner.class ? banner.class : '')"
|
[ngClass]="[
|
||||||
|
banner.type === 'history' ? 'history-mode-indicator' : '',
|
||||||
|
banner.class ? banner.class : '',
|
||||||
|
banner.largerOnMobileView ? 'larger-on-mobile' : ''
|
||||||
|
]"
|
||||||
[ngSwitch]="banner.type"
|
[ngSwitch]="banner.type"
|
||||||
[style.background-color]="banner.bgColor"
|
|
||||||
[style.color]="banner.color"
|
|
||||||
>
|
>
|
||||||
<ng-container *ngSwitchCase="'history'">
|
<ng-container *ngSwitchCase="'history'">
|
||||||
<span translate>You are using the history mode of OpenSlides. Changes will not be saved.</span>
|
<span translate>You are using the history mode of OpenSlides. Changes will not be saved.</span>
|
||||||
@ -12,7 +14,7 @@
|
|||||||
<a (click)="timeTravel.resumeTime()" translate>Exit</a>
|
<a (click)="timeTravel.resumeTime()" translate>Exit</a>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngSwitchDefault>
|
<ng-container *ngSwitchDefault>
|
||||||
<a [routerLink]="banner.link" [style.cursor]="banner.link ? 'pointer' : 'default'">
|
<a class="banner-link" [routerLink]="banner.link" [style.cursor]="banner.link ? 'pointer' : 'default'">
|
||||||
<mat-icon>{{ banner.icon }}</mat-icon> <span>{{ banner.text }}</span>
|
<mat-icon>{{ banner.icon }}</mat-icon> <span>{{ banner.text }}</span>
|
||||||
</a>
|
</a>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
|
@import '../../../../assets/styles/media-queries.scss';
|
||||||
|
|
||||||
.banner {
|
.banner {
|
||||||
|
&.larger-on-mobile {
|
||||||
|
@include set-breakpoint-lower(sm) {
|
||||||
|
height: 40px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
position: relative; // was fixed before to prevent the overflow
|
position: relative; // was fixed before to prevent the overflow
|
||||||
height: 20px;
|
height: 20px;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
@ -7,12 +15,18 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
border-bottom: 1px solid white;
|
||||||
|
|
||||||
a {
|
a {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: white;
|
color: white;
|
||||||
|
&.banner-link {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mat-icon {
|
mat-icon {
|
||||||
|
Loading…
Reference in New Issue
Block a user