calls in administration page to delete things

This commit is contained in:
Baptiste Lemoine 2020-01-16 14:37:11 +01:00
parent ce4c3cb000
commit bae3f19af2
10 changed files with 352 additions and 170 deletions

View File

@ -44,12 +44,14 @@ import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {ConfigService} from "./services/config.service";
import {PollService} from "./services/poll.service";
import {ToastModule} from 'primeng/toast';
import {MessageModule, MessageService} from "primeng";
import {ConfirmationService, MessageModule, MessageService} from "primeng";
import {PollDisplayComponent} from './pages/poll-display/poll-display.component';
import {VotingComponent} from './pages/voting/voting.component';
import {VotingCommentComponent} from './pages/voting/voting-comment/voting-comment.component';
import {ResettableInputDirective} from './ui/directives/resettable-input.directive';
import {ClipboardModule} from "ngx-clipboard";
import {ErasableInputComponent} from './ui/erasable-input/erasable-input.component';
import {ConfirmDialogModule} from 'primeng/confirmdialog';
export class MyMissingTranslationHandler implements MissingTranslationHandler {
handle(params: MissingTranslationHandlerParams) {
@ -92,9 +94,11 @@ export function HttpLoaderFactory(http: HttpClient) {
VotingComponent,
VotingCommentComponent,
ResettableInputDirective,
ErasableInputComponent,
],
imports: [
ConfirmDialogModule,
ClipboardModule,
CommonModule,
BrowserModule,
@ -119,7 +123,7 @@ export function HttpLoaderFactory(http: HttpClient) {
FormsModule,
RouterModule.forRoot(Routes)
],
providers: [TranslateService, ConfigService, PollService, MessageService],
providers: [TranslateService, ConfigService, PollService, MessageService, ConfirmationService],
bootstrap: [AppComponent]
})
export class AppModule {

View File

@ -1,164 +1,193 @@
<form>
<h1>Nom du sondage</h1>
<h1>Nom du sondage</h1>
<!--Infos-->
<h2>{{"admin.info_section_title"|translate}}</h2>
<!--Infos-->
<h2>{{"admin.info_section_title"|translate}}</h2>
<label for="title">
{{"admin.choose_title"|translate}}
</label>
<input type="text" name="title">
<label for="title">
{{"admin.choose_title"|translate}}
</label>
<input type="text" name="title">
<label for="desc">
{{"admin.description"|translate}}
</label>
<textarea name="desc"> </textarea>
<label for="desc">
{{"admin.description"|translate}}
</label>
<textarea name="desc"> </textarea>
<label for="name">
{{"creation.name"|translate}}
</label>
<input type="text" name="name">
<label for="name">
{{"creation.name"|translate}}
</label>
<input type="text" name="name">
<!--Params-->
<h2>{{"admin.settings_section_title"|translate}}</h2>
<h3>{{"visibility.title"|translate}}</h3>
<!--Params-->
<h2>{{"admin.settings_section_title"|translate}}</h2>
<h3>{{"visibility.title"|translate}}</h3>
<section class="row">
<label for="answer-visible">
{{"visibility.visibility_want"|translate}}
</label>
<select name="answer-visible">
<option value="all" selected>
{{"visibility.visibility_link"|translate}}
</option>
<option value="per">
{{"visibility.visibility_nobody"|translate}}
</option>
</select>
<label for="answer-visible">
{{"visibility.visibility_see"|translate}}
</label>
</section>
<section class="row">
<label for="answer-visible">
{{"visibility.visibility_want"|translate}}
</label>
<select name="answer-visible">
<option value="all" selected>
{{"visibility.visibility_link"|translate}}
</option>
<option value="per">
{{"visibility.visibility_nobody"|translate}}
</option>
</select>
<label for="answer-visible">
{{"visibility.visibility_see"|translate}}
</label>
</section>
<h3>{{"visibility.votes"|translate}}</h3>
<section>
<label for="vote-date">
{{"visibility.archiving"|translate}}
</label>
<input type="date" name="vote-date">
</section>
<section>
<label for="alter-vote">
{{"visibility.archiving_start"|translate}}
</label>
<select name="alter-vote">
<option value="yes" selected>
{{"visibility.archiving_can"|translate}}
</option>
<option value="no">
{{"visibility.archiving_can_not"|translate}}
</option>
</select>
<label for="type-vote">
{{"visibility.archiving_end"|translate}}
</label>
<select name="type-vote">
<option value="solo" selected>
{{"visibility.modfiy_their"|translate}}
</option>
<option value="all">
{{"visibility.modfiy_everyone"|translate}}
</option>
</select>
</section>
<h3>{{"visibility.votes"|translate}}</h3>
<section>
<label for="vote-date">
{{"visibility.archiving"|translate}}
</label>
<input type="date" name="vote-date">
</section>
<section>
<label for="alter-vote">
{{"visibility.archiving_start"|translate}}
</label>
<select name="alter-vote">
<option value="yes" selected>
{{"visibility.archiving_can"|translate}}
</option>
<option value="no">
{{"visibility.archiving_can_not"|translate}}
</option>
</select>
<label for="type-vote">
{{"visibility.archiving_end"|translate}}
</label>
<select name="type-vote">
<option value="solo" selected>
{{"visibility.modfiy_their"|translate}}
</option>
<option value="all">
{{"visibility.modfiy_everyone"|translate}}
</option>
</select>
</section>
<label for="del-vote">
{{"admin.votes_deletion_desc"|translate}}
</label>
<input class="btn btn--alert btn--outline" type="submit"
name="del-vote" value="{{'admin.votes_deletion_btn'|translate}}">
<label for="del-vote">
{{"admin.votes_deletion_desc"|translate}}
</label>
<button class="btn btn--alert btn--outline"
(click)="config.deleteVotes()"
>
<i class="fa fa-trash"></i>
{{'admin.votes_deletion_btn'|translate}}
<i class="fa fa-object-group"></i></button>
<h3>{{"admin.comments_deletion_title"|translate}}</h3>
<label for="del-com">
{{"admin.comments_deletion_desc"|translate}}
</label>
<input class="btn btn--alert btn--outline" type="submit"
name="del-com" value="{{'admin.comments_deletion_btn'|translate}}">
<h3>{{"admin.comments_deletion_title"|translate}}</h3>
<label for="del-com">
{{"admin.comments_deletion_desc"|translate}}
</label>
<h3>{{"admin.archiving_title"|translate}}</h3>
<section class="row">
<label for="arch">
{{"admin.archiving_desc"|translate}}
</label>
<input type="date" name="arch">
</section>
<button class="btn btn--alert btn--outline"
(click)="config.deleteComments()"
>
<i class="fa fa-trash"></i>
<h3>{{"visibility.access"|translate}}</h3>
<section class="row">
<label for="password">Je</label>
<select name="password">
<option value="yes" selected>
{{"visibility.access_want_yes"|translate}}
</option>
<option value="no">
{{"visibility.access_want_no"|translate}}
</option>
</select>
<label for="alter-vote">
{{"visibility.access_protect"|translate}}
</label>
</section>
{{'admin.comments_deletion_btn'|translate}}
<i class="fa fa-comments-o"></i></button>
<h3>{{"admin.deletion"|translate}}</h3>
<label for="del"> {{"admin.deletion_desc"|translate}} </label>
<input class="btn btn--alert" type="submit"
name="del" value="{{'admin.deletion_btn'|translate}}">
<h3>{{"admin.archiving_title"|translate}}</h3>
<section class="row">
<label for="arch">
{{"admin.archiving_desc"|translate}}
</label>
<input type="date" name="arch">
</section>
<!-- Access link -->
<h2>{{"admin.link"|translate}}</h2>
<h3>{{"admin.link_admin"|translate}}</h3>
<h3>{{"visibility.access"|translate}}</h3>
<section class="row">
<label for="password">Je</label>
<select name="password">
<option value="yes" selected>
{{"visibility.access_want_yes"|translate}}
</option>
<option value="no">
{{"visibility.access_want_no"|translate}}
</option>
</select>
<label for="alter-vote">
{{"visibility.access_protect"|translate}}
</label>
</section>
<label for="copy-link-admin">
{{"admin.link_admin_desc"|translate}}
https://framadate.org/urladmindusondage
</label>
<input class="btn btn--mini" type="submit" name="copy-link-admin"
value="{{'admin.copy_link'|translate}}">
<a href="#" class="next">{{"admin.link_admin_btn"|translate}}</a>
<h3>{{"admin.deletion"|translate}}</h3>
<label for="del"> {{"admin.deletion_desc"|translate}} </label>
<input class="btn btn--alert" type="submit"
name="del" value="{{'admin.deletion_btn'|translate}}">
<h3>{{"admin.polled_people"|translate}}</h3>
<label for="copy-link">
{{"admin.polled_people_desc"|translate}}
https://framadate.org/urladmindusondage</label>
<input class="btn btn--mini" type="submit" name="copy-link"
value="{{'admin.copy_link'|translate}}">
<a href="#" class="next">{{"admin.polled_people_btn"|translate}}</a>
<!-- Access link -->
<h2>{{"admin.link"|translate}}</h2>
<h3>{{"admin.link_admin"|translate}}</h3>
<h3>{{"admin.email_links"|translate}}</h3>
<label for="mail">{{"admin.email_links_desc"|translate}}</label>
<input type="email" name="mail">
<input class="btn btn--mini" type="submit" name="send-mail"
value="{{'admin.email_links_btn'|translate}}">
<label for="copy-link-admin">
{{"admin.link_admin_desc"|translate}}
https://framadate.org/urladmindusondage
</label>
<input class="btn btn--mini" type="submit" name="copy-link-admin"
value="{{'admin.copy_link'|translate}}">
<a href="#" class="next">{{"admin.link_admin_btn"|translate}}</a>
<section class="deletion">
{{"admin.deletion"|translate}}
{{"admin.deletion_desc"|translate}}
{{"admin.deletion_btn"|translate}}
</section>
<h3>{{"admin.polled_people"|translate}}</h3>
<label for="copy-link">
{{"admin.polled_people_desc"|translate}}
{{config.urlPublic}}</label>
<input class="btn btn--mini" type="submit" name="copy-link"
value="{{'admin.copy_link'|translate}}">
<a href="#" class="next">{{"admin.polled_people_btn"|translate}}</a>
<section class="links">
{{"admin.link"|translate}}
{{"admin.link_admin"|translate}}
{{"admin.link_admin_desc"|translate}}
{{"admin.link_admin_btn"|translate}}
{{"admin.copy_link"|translate}}
<h3>{{"admin.email_links"|translate}}</h3>
<label for="mail">{{"admin.email_links_desc"|translate}}</label>
<input type="email" name="mail">
<input class="btn btn--mini" type="submit" name="send-mail"
value="{{'admin.email_links_btn'|translate}}">
{{"admin.polled_people"|translate}}
{{"admin.polled_people_desc"|translate}}
{{"admin.polled_people_btn"|translate}}
{{"admin.email_links"|translate}}
{{"admin.email_links_desc"|translate}}
{{"admin.email_links_key"|translate}}
{{"admin.email_links_btn"|translate}}
</section>
<section class="deletion">
<h2>
{{"admin.deletion"|translate}}
</h2>
{{"admin.deletion_desc"|translate}}
<button class="btn btn--danger" (click)="config.deletePoll()">
<i class="fa fa-trash"></i>
<i class="fa fa-warning"></i>
{{"admin.deletion_btn"|translate}}
</button>
<button class="btn btn--danger" (click)="config.deleteComments()">
<i class="fa fa-trash"></i>
<i class="fa fa-warning"></i>
{{"admin.comments_deletion_btn"|translate}}
</button>
<button class="btn btn--danger" (click)="config.deleteVotes()">
<i class="fa fa-trash"></i>
<i class="fa fa-warning"></i>
{{"admin.votes_btn_votes"|translate}}
</button>
</section>
<section class="links">
{{"admin.link"|translate}}
{{"admin.link_admin"|translate}}
{{"admin.link_admin_desc"|translate}}
{{"admin.link_admin_btn"|translate}}
{{"admin.copy_link"|translate}}
{{"admin.polled_people"|translate}}
{{"admin.polled_people_desc"|translate}}
{{"admin.polled_people_btn"|translate}}
{{"admin.email_links"|translate}}
{{"admin.email_links_desc"|translate}}
{{"admin.email_links_key"|translate}}
{{"admin.email_links_btn"|translate}}
</section>
</form>
<p-confirmDialog header="Confirmation" icon="pi pi-exclamation-triangle"></p-confirmDialog>

View File

@ -8,7 +8,7 @@ import {ConfigService} from '../../services/config.service';
})
export class AdminComponent implements OnInit {
constructor() { }
constructor(private config : ConfigService) { }
ngOnInit() {
}

View File

@ -86,6 +86,7 @@
required="required"
type="email"
/>
<framadate-erasable-input [(inputModel)]="config.myEmail"></framadate-erasable-input>
</div>
<button

View File

@ -2,7 +2,8 @@ import {Injectable} from '@angular/core';
import {PollConfig} from '../config/PollConfig';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {environment} from "../../environments/environment";
import {MessageService} from 'primeng/api';
import {ConfirmationService, MessageService} from 'primeng/api';
import {Router} from "@angular/router";
/**
* le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée
@ -18,7 +19,10 @@ export class ConfigService extends PollConfig {
constructor(private http: HttpClient,
private messageService: MessageService) {
private messageService: MessageService,
private router: Router,
private confirmationService: ConfirmationService,
) {
super();
}
@ -191,6 +195,10 @@ export class ConfigService extends PollConfig {
findLocalStorageData() {
// TODO check if the person has a key to retrieve her polls
if (localStorage) {
console.log('localStorage', localStorage)
}
}
@ -280,28 +288,6 @@ export class ConfigService extends PollConfig {
);
}
/**
* UPDATE
* /api/v1/poll/{id}/vote
* @param voteStack
*/
updatePoll(voteStack: any) {
this.http.put(
`${this.baseHref}/poll/${this.pollId}`,
voteStack,
this.makeHeaders()
)
.subscribe((res: any) => {
this.messageService.add({
severity: 'success',
summary: 'Sondage mis à jour',
});
this.myPolls = res;
}, (e) => {
this.handleError(e)
}
);
}
/**
* POST
@ -370,4 +356,104 @@ export class ConfigService extends PollConfig {
* administrator calls
*/
deleteComments() {
// prompt for confirmation
this.confirmationService.confirm({
message: 'Are you sure that you want to completely delete the comments of this poll (' + this.title + ') permanentely?',
accept: () => {
this.http.delete(
`${this.baseHref}/poll/${this.pollId}/comments`,
this.makeHeaders())
.subscribe((res: any) => {
this.messageService.add({
severity: 'success',
summary: 'Commentaires bien supprimés',
detail: 'Commentaires du sondage "' + this.title + '" supprimé'
});
}, (e) => {
this.handleError(e)
}
);
}
});
}
deleteVotes() {
// prompt for confirmation
this.confirmationService.confirm({
message: 'Are you sure that you want to completely delete the votes of this poll (' + this.title + ') permanentely?',
accept: () => {
this.http.delete(
`${this.baseHref}/poll/${this.pollId}/votes`,
this.makeHeaders())
.subscribe((res: any) => {
this.messageService.add({
severity: 'success',
summary: 'Votes bien supprimés',
detail: 'Votes du sondage "' + this.title + '" supprimé'
});
}, (e) => {
this.handleError(e)
}
);
}
});
}
deletePoll() {
if (!this.pollId) {
this.messageService.add({
summary: 'this poll is not administrable, it has no ID',
severity: 'warning'
});
return;
}
let self = this;
// prompt for confirmation
this.confirmationService.confirm({
message: 'Are you sure that you want to completely delete this poll (' + self.title + ') and all is data permanentely?',
accept: () => {
this.http.delete(
`${this.baseHref}/poll/${this.pollId}`,
this.makeHeaders())
.subscribe((res: any) => {
this.messageService.add({
severity: 'success',
summary: 'Sondage bien supprimé',
detail: 'sondage "' + this.title + '" supprimé'
});
this.router.navigate(['home']);
}, (e) => {
this.handleError(e)
}
);
}
});
}
/**
* UPDATE
* /api/v1/poll/{id}/vote
* @param voteStack
*/
updatePoll(voteStack: any) {
this.http.put(
`${this.baseHref}/poll/${this.pollId}`,
voteStack,
this.makeHeaders()
)
.subscribe((res: any) => {
this.messageService.add({
severity: 'success',
summary: 'Sondage mis à jour',
});
this.myPolls = res;
}, (e) => {
this.handleError(e)
}
);
}
}

View File

@ -1,5 +1,8 @@
import {Directive} from '@angular/core';
/**
* add a button on an input which deletes its value
*/
@Directive({
selector: '[framadateResettableInput]'
})

View File

@ -0,0 +1,3 @@
<button class="erase" (click)="eraseInput()">
<i class="fa fa-times"></i>
</button>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ErasableInputComponent } from './erasable-input.component';
describe('ErasableInputComponent', () => {
let component: ErasableInputComponent;
let fixture: ComponentFixture<ErasableInputComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ErasableInputComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ErasableInputComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,31 @@
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
@Component({
selector: 'framadate-erasable-input',
templateUrl: './erasable-input.component.html',
styleUrls: ['./erasable-input.component.scss']
})
export class ErasableInputComponent implements OnInit {
@Output() inputModelChange = new EventEmitter();
@Input() get inputModel() {
return this.inputModel;
}
set inputModel(val) {
// this.inputModel = val;
}
constructor() {
}
ngOnInit() {
}
eraseInput() {
this.inputModel = '';
this.inputModelChange.emit(this.inputModel);
}
}