mirror of
https://framagit.org/framasoft/framadate/funky-framadate-front.git
synced 2023-08-25 13:53:14 +02:00
send stack of votes button linked to api
This commit is contained in:
parent
3abef619c8
commit
7a83beae8e
@ -2,9 +2,12 @@ export class Vote {
|
|||||||
public choice_id: number = 0;
|
public choice_id: number = 0;
|
||||||
public value: string = ''; // valeur de réponse
|
public value: string = ''; // valeur de réponse
|
||||||
|
|
||||||
constructor(choice_id?) {
|
constructor(choice_id?, value?) {
|
||||||
if (choice_id) {
|
if (choice_id) {
|
||||||
this.choice_id = choice_id;
|
this.choice_id = choice_id;
|
||||||
}
|
}
|
||||||
|
if (value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { ToastService } from './toast.service';
|
import { ToastService } from './toast.service';
|
||||||
import { LoaderService } from './loader.service';
|
import { LoaderService } from './loader.service';
|
||||||
|
import { Stack } from '../models/stack.model';
|
||||||
|
|
||||||
const apiVersion = environment.api.versionToUse;
|
const apiVersion = environment.api.versionToUse;
|
||||||
const currentApiRoutes = environment.api.version[apiVersion];
|
const currentApiRoutes = environment.api.version[apiVersion];
|
||||||
@ -30,8 +31,11 @@ export class ApiService {
|
|||||||
private readonly usersEndpoint = apiEndpoints.users.name;
|
private readonly usersEndpoint = apiEndpoints.users.name;
|
||||||
private readonly usersPollsEndpoint = apiEndpoints.users.polls.name;
|
private readonly usersPollsEndpoint = apiEndpoints.users.polls.name;
|
||||||
private readonly usersPollsSendEmailEndpoint = apiEndpoints.users.polls.sendEmail.name;
|
private readonly usersPollsSendEmailEndpoint = apiEndpoints.users.polls.sendEmail.name;
|
||||||
|
private baseHref: string;
|
||||||
|
|
||||||
constructor(private http: HttpClient, private loader: LoaderService, private toastService: ToastService) {
|
constructor(private http: HttpClient, private loader: LoaderService, private toastService: ToastService) {
|
||||||
|
this.baseHref = apiBaseHref;
|
||||||
|
|
||||||
this.axiosInstance = axios.create({ baseURL: apiBaseHref });
|
this.axiosInstance = axios.create({ baseURL: apiBaseHref });
|
||||||
this.axiosInstance.defaults.timeout = 2500;
|
this.axiosInstance.defaults.timeout = 2500;
|
||||||
this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json';
|
this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json';
|
||||||
@ -91,9 +95,9 @@ export class ApiService {
|
|||||||
public async createPoll(poll: Poll): Promise<Subscription> {
|
public async createPoll(poll: Poll): Promise<Subscription> {
|
||||||
// this.loader.setStatus(true);
|
// this.loader.setStatus(true);
|
||||||
console.log('createPoll config', poll);
|
console.log('createPoll config', poll);
|
||||||
const baseHref = this.useDevLocalServer ? 'http://localhost:8000' : apiBaseHref;
|
|
||||||
return this.axiosInstance.post(
|
return this.axiosInstance.post(
|
||||||
`${baseHref}${currentApiRoutes['api_new_poll']}`,
|
`${this.baseHref}${currentApiRoutes['api_new_poll']}`,
|
||||||
poll,
|
poll,
|
||||||
ApiService.makeHeaders()
|
ApiService.makeHeaders()
|
||||||
);
|
);
|
||||||
@ -108,6 +112,24 @@ export class ApiService {
|
|||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a new vote stack
|
||||||
|
* @param poll
|
||||||
|
* @param vote_stack
|
||||||
|
*/
|
||||||
|
public async sendVoteStackOfPoll(poll: Poll, vote_stack: Stack) {
|
||||||
|
// api_new_vote_stack POST ANY ANY /api/v1/poll/{id}/answer
|
||||||
|
|
||||||
|
console.log('vote_stack', vote_stack);
|
||||||
|
console.log('this.baseHref', this.baseHref);
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.axiosInstance.post(`${this.pollsEndpoint}/${poll.custom_url}/answer`, vote_stack);
|
||||||
|
} catch (error) {
|
||||||
|
ApiService.handleError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// READ //
|
// READ //
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import { Theme } from '../enums/theme.enum';
|
|||||||
import { Stack } from '../models/stack.model';
|
import { Stack } from '../models/stack.model';
|
||||||
import { Choice } from '../models/choice.model';
|
import { Choice } from '../models/choice.model';
|
||||||
import { Vote } from '../models/vote.model';
|
import { Vote } from '../models/vote.model';
|
||||||
|
import { environment } from '../../../environments/environment';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@ -27,7 +28,11 @@ export class StorageService {
|
|||||||
this.vote_stack.votes = [];
|
this.vote_stack.votes = [];
|
||||||
|
|
||||||
for (let choice of choices_list) {
|
for (let choice of choices_list) {
|
||||||
this.vote_stack.votes.push(new Vote(choice.id));
|
if (environment.autofill) {
|
||||||
|
this.vote_stack.votes.push(new Vote(choice.id, 'yes'));
|
||||||
|
} else {
|
||||||
|
this.vote_stack.votes.push(new Vote(choice.id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import { DateService } from '../../core/services/date.service';
|
|||||||
import { PollUtilities } from '../old-stuff/config/PollUtilities';
|
import { PollUtilities } from '../old-stuff/config/PollUtilities';
|
||||||
import { Comment } from '../../core/models/comment.model';
|
import { Comment } from '../../core/models/comment.model';
|
||||||
import { StorageService } from '../../core/services/storage.service';
|
import { StorageService } from '../../core/services/storage.service';
|
||||||
|
import { ApiService } from '../../core/services/api.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-consultation',
|
selector: 'app-consultation',
|
||||||
@ -35,6 +36,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
|||||||
private utils: PollUtilities,
|
private utils: PollUtilities,
|
||||||
private _Activatedroute: ActivatedRoute,
|
private _Activatedroute: ActivatedRoute,
|
||||||
public storageService: StorageService,
|
public storageService: StorageService,
|
||||||
|
public api: ApiService,
|
||||||
public pollService: PollService,
|
public pollService: PollService,
|
||||||
public dateService: DateService,
|
public dateService: DateService,
|
||||||
private modalService: ModalService
|
private modalService: ModalService
|
||||||
@ -72,12 +74,16 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateVote(myVoteStack: boolean) {
|
updateVote() {
|
||||||
alert('TODO');
|
alert('TODO');
|
||||||
}
|
}
|
||||||
|
|
||||||
addVoteStack() {
|
addVoteStack() {
|
||||||
alert('TODO');
|
this.api.sendVoteStackOfPoll(this.poll, this.storageService.vote_stack).then((resp) => {
|
||||||
|
console.log('resp', resp);
|
||||||
|
|
||||||
|
this.api.getPollBySlug(this.poll.custom_url);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,7 @@ const apiV1 = {
|
|||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: true,
|
production: true,
|
||||||
|
autofill: true,
|
||||||
appTitle: 'FramaDate Funky',
|
appTitle: 'FramaDate Funky',
|
||||||
appVersion: '2.1.0',
|
appVersion: '2.1.0',
|
||||||
appLogo: 'assets/img/logo.png',
|
appLogo: 'assets/img/logo.png',
|
||||||
|
@ -10,12 +10,14 @@ const apiV1 = {
|
|||||||
baseHref: 'http://localhost:8000/api/v1',
|
baseHref: 'http://localhost:8000/api/v1',
|
||||||
api_new_poll: '/poll/',
|
api_new_poll: '/poll/',
|
||||||
api_get_poll: '/poll/{id}',
|
api_get_poll: '/poll/{id}',
|
||||||
|
api_new_vote_stack: '/poll/{id}/answer',
|
||||||
'api_test-mail-poll': '/api/v1/poll/mail/test-mail-poll/{emailChoice}',
|
'api_test-mail-poll': '/api/v1/poll/mail/test-mail-poll/{emailChoice}',
|
||||||
'app.swagger': '/api/doc.json',
|
'app.swagger': '/api/doc.json',
|
||||||
};
|
};
|
||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
|
autofill: true,
|
||||||
appTitle: 'FramaDate Funky',
|
appTitle: 'FramaDate Funky',
|
||||||
appVersion: '2.1.0',
|
appVersion: '2.1.0',
|
||||||
appLogo: 'assets/img/logo.png',
|
appLogo: 'assets/img/logo.png',
|
||||||
|
Loading…
Reference in New Issue
Block a user