forked from tykayn/funky-framadate-front
⚡ export format json public
This commit is contained in:
parent
acb091802c
commit
e2c388da9e
@ -23,6 +23,7 @@ export class AppComponent {
|
|||||||
this.detectCurrentTabOnRouteChange();
|
this.detectCurrentTabOnRouteChange();
|
||||||
|
|
||||||
this.isDevelopmentEnv = !environment.production
|
this.isDevelopmentEnv = !environment.production
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
detectCurrentTabOnRouteChange() {
|
detectCurrentTabOnRouteChange() {
|
||||||
|
@ -5,8 +5,16 @@
|
|||||||
class='btn btn--primary'
|
class='btn btn--primary'
|
||||||
(click)='config.execStuff()'
|
(click)='config.execStuff()'
|
||||||
*ngIf='config.isAdmin' >
|
*ngIf='config.isAdmin' >
|
||||||
launch !
|
launch admin action execStuff !
|
||||||
</button >
|
</button >
|
||||||
|
<button
|
||||||
|
class='btn btn--primary'
|
||||||
|
(click)='config.exportJson()'
|
||||||
|
*ngIf='config.isAdmin' >
|
||||||
|
<i class="fa fa-file-archive-o"></i>
|
||||||
|
export CSV
|
||||||
|
</button >
|
||||||
|
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class='loading'
|
class='loading'
|
||||||
|
@ -62,11 +62,11 @@ export class ConfigService extends PollConfig {
|
|||||||
if (storage) {
|
if (storage) {
|
||||||
const preferences = storage.getItem('FramadateConfig');
|
const preferences = storage.getItem('FramadateConfig');
|
||||||
|
|
||||||
if(preferences){
|
if (preferences) {
|
||||||
|
|
||||||
const parsed = JSON.parse(preferences);
|
const parsed = JSON.parse(preferences);
|
||||||
console.log('parsed', parsed)
|
console.log('parsed', parsed);
|
||||||
this.preferences = parsed
|
this.preferences = parsed;
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -81,7 +81,7 @@ export class ConfigService extends PollConfig {
|
|||||||
if (this.preferences) {
|
if (this.preferences) {
|
||||||
|
|
||||||
this.preferences[key] = value;
|
this.preferences[key] = value;
|
||||||
if(key === 'themeName' && this.themeChoices.includes(value)){
|
if (key === 'themeName' && this.themeChoices.includes(value)) {
|
||||||
this.themeSelected = this.themeChoices.indexOf(value);
|
this.themeSelected = this.themeChoices.indexOf(value);
|
||||||
this.preferences.themeClass =
|
this.preferences.themeClass =
|
||||||
this.themeClass = `theme-${value}`;
|
this.themeClass = `theme-${value}`;
|
||||||
@ -593,7 +593,6 @@ export class ConfigService extends PollConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO
|
|
||||||
* export all the poll data available to the public as a CSV single file
|
* export all the poll data available to the public as a CSV single file
|
||||||
*/
|
*/
|
||||||
exportCSV() {
|
exportCSV() {
|
||||||
@ -666,6 +665,36 @@ export class ConfigService extends PollConfig {
|
|||||||
link.click(); // This will download the data file named "my_data.csv".
|
link.click(); // This will download the data file named "my_data.csv".
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exportJson() {
|
||||||
|
this.download('export_poll_' + this.pollSlug + '.json', JSON.stringify(
|
||||||
|
{
|
||||||
|
export_date: new Date(),
|
||||||
|
creation_date: this.creationDate,
|
||||||
|
title: this.title,
|
||||||
|
description: this.description,
|
||||||
|
pollType: this.pollType,
|
||||||
|
urlPublic: this.urlPublic,
|
||||||
|
currentPoll: this.currentPoll,
|
||||||
|
votes: this.voteChoices
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
download(filename, text) {
|
||||||
|
var element = document.createElement('a');
|
||||||
|
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
||||||
|
element.setAttribute('download', filename);
|
||||||
|
|
||||||
|
element.style.display = 'none';
|
||||||
|
document.body.appendChild(element);
|
||||||
|
|
||||||
|
element.click();
|
||||||
|
|
||||||
|
document.body.removeChild(element);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
print() {
|
print() {
|
||||||
alert('TODO');
|
alert('TODO');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user