From fae7a40aebc4266260c8cb0dcac929ac03500590 Mon Sep 17 00:00:00 2001 From: aka Date: Sun, 13 May 2018 20:47:08 -0300 Subject: [PATCH 1/2] Adds an option to export follows --- src/components/user_settings/user_settings.js | 29 +++++++++++++++++++ .../user_settings/user_settings.vue | 7 +++++ src/i18n/messages.js | 5 +++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 25ee1f35..602052ca 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -8,6 +8,7 @@ const UserSettings = { followList: null, followImportError: false, followsImported: false, + enableFollowsExport: true, uploading: [ false, false, false, false ], previews: [ null, null, null ] } @@ -137,6 +138,34 @@ const UserSettings = { this.uploading[3] = false }) }, + /* This function takes an Array of Users + * and outputs a file with all the addresses for the user to download + */ + exportPeople(Users) { + // Get all the friends addresses + var UserAddresses = Users.map(function(user) { + // check is it's a local user + if(user && user.is_local) { + // append the instance address + user.screen_name += '@' + location.hostname; + } + return user.screen_name; + }).join('\n'); + // Make the user download the file + var fileToDownload = document.createElement('a'); + fileToDownload.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(UserAddresses)); + fileToDownload.setAttribute('download', 'friends.csv'); + fileToDownload.style.display = 'none'; + document.body.appendChild(fileToDownload); + fileToDownload.click(); + document.body.removeChild(fileToDownload); + }, + exportFollows() { + this.enableFollowsExport = false; + this.$store.state.api.backendInteractor + .fetchFriends({id: this.$store.state.users.currentUser.id}) + .then(this.exportPeople); + }, followListChange () { // eslint-disable-next-line no-undef let formData = new FormData() diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index ed1864cc..184d158d 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -66,6 +66,13 @@

{{$t('settings.follow_import_error')}}

+
+

{{$t('settings.follow_export')}}

+ +
+
+

{{$t('settings.follow_export_processing')}}

+
diff --git a/src/i18n/messages.js b/src/i18n/messages.js index 168548cf..473fd9b1 100644 --- a/src/i18n/messages.js +++ b/src/i18n/messages.js @@ -288,7 +288,10 @@ const en = { follow_import: 'Follow import', import_followers_from_a_csv_file: 'Import follows from a csv file', follows_imported: 'Follows imported! Processing them will take a while.', - follow_import_error: 'Error importing followers' + follow_import_error: 'Error importing followers', + follow_export: 'Follow export', + follow_export_processing: 'Processing, you\'ll soon be aked to download your file', + follow_export_button: 'Export your follows to a csv file' }, notifications: { notifications: 'Notifications', From fed87815833bfb847be192b79782f3edca99cf5f Mon Sep 17 00:00:00 2001 From: aka Date: Wed, 16 May 2018 19:51:52 -0300 Subject: [PATCH 2/2] fix linting --- src/components/user_settings/user_settings.js | 43 ++++++++++--------- src/i18n/messages.js | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index 602052ca..2c08b2f8 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -141,30 +141,33 @@ const UserSettings = { /* This function takes an Array of Users * and outputs a file with all the addresses for the user to download */ - exportPeople(Users) { + exportPeople (users, filename) { // Get all the friends addresses - var UserAddresses = Users.map(function(user) { - // check is it's a local user - if(user && user.is_local) { - // append the instance address - user.screen_name += '@' + location.hostname; - } - return user.screen_name; - }).join('\n'); + var UserAddresses = users.map(function (user) { + // check is it's a local user + if (user && user.is_local) { + // append the instance address + // eslint-disable-next-line no-undef + user.screen_name += '@' + location.hostname + } + return user.screen_name + }).join('\n') // Make the user download the file - var fileToDownload = document.createElement('a'); - fileToDownload.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(UserAddresses)); - fileToDownload.setAttribute('download', 'friends.csv'); - fileToDownload.style.display = 'none'; - document.body.appendChild(fileToDownload); - fileToDownload.click(); - document.body.removeChild(fileToDownload); + var fileToDownload = document.createElement('a') + fileToDownload.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(UserAddresses)) + fileToDownload.setAttribute('download', filename) + fileToDownload.style.display = 'none' + document.body.appendChild(fileToDownload) + fileToDownload.click() + document.body.removeChild(fileToDownload) }, - exportFollows() { - this.enableFollowsExport = false; + exportFollows () { + this.enableFollowsExport = false this.$store.state.api.backendInteractor - .fetchFriends({id: this.$store.state.users.currentUser.id}) - .then(this.exportPeople); + .fetchFriends({id: this.$store.state.users.currentUser.id}) + .then(function (friendList) { + this.exportPeople(friendList, 'friends.csv') + }.bind(this)) }, followListChange () { // eslint-disable-next-line no-undef diff --git a/src/i18n/messages.js b/src/i18n/messages.js index 473fd9b1..bb3f2d39 100644 --- a/src/i18n/messages.js +++ b/src/i18n/messages.js @@ -290,7 +290,7 @@ const en = { follows_imported: 'Follows imported! Processing them will take a while.', follow_import_error: 'Error importing followers', follow_export: 'Follow export', - follow_export_processing: 'Processing, you\'ll soon be aked to download your file', + follow_export_processing: 'Processing, you\'ll soon be asked to download your file', follow_export_button: 'Export your follows to a csv file' }, notifications: {