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

@ -75,15 +75,25 @@
<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}}">
<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}}">
<button class="btn btn--alert btn--outline"
(click)="config.deleteComments()"
>
<i class="fa fa-trash"></i>
{{'admin.comments_deletion_btn'|translate}}
<i class="fa fa-comments-o"></i></button>
<h3>{{"admin.archiving_title"|translate}}</h3>
<section class="row">
@ -129,7 +139,7 @@
<h3>{{"admin.polled_people"|translate}}</h3>
<label for="copy-link">
{{"admin.polled_people_desc"|translate}}
https://framadate.org/urladmindusondage</label>
{{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>
@ -141,9 +151,27 @@
value="{{'admin.email_links_btn'|translate}}">
<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">
@ -162,3 +190,4 @@
{{"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);
}
}