Merge branch 'feature/follows-export' into 'develop'

Adds an option to export follows (fixed)

See merge request pleroma/pleroma-fe!261
This commit is contained in:
lambda 2018-05-18 07:51:00 +00:00
commit 166d9294c4
3 changed files with 43 additions and 1 deletions

View File

@ -8,6 +8,7 @@ const UserSettings = {
followList: null, followList: null,
followImportError: false, followImportError: false,
followsImported: false, followsImported: false,
enableFollowsExport: true,
uploading: [ false, false, false, false ], uploading: [ false, false, false, false ],
previews: [ null, null, null ] previews: [ null, null, null ]
} }
@ -137,6 +138,37 @@ const UserSettings = {
this.uploading[3] = false 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, 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
// 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', filename)
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(function (friendList) {
this.exportPeople(friendList, 'friends.csv')
}.bind(this))
},
followListChange () { followListChange () {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
let formData = new FormData() let formData = new FormData()

View File

@ -66,6 +66,13 @@
<p>{{$t('settings.follow_import_error')}}</p> <p>{{$t('settings.follow_import_error')}}</p>
</div> </div>
</div> </div>
<div class="setting-item" v-if="enableFollowsExport">
<h3>{{$t('settings.follow_export')}}</h3>
<button class="btn btn-default" @click="exportFollows">{{$t('settings.follow_export_button')}}</button>
</div>
<div class="setting-item" v-else>
<h3>{{$t('settings.follow_export_processing')}}</h3>
</div>
</div> </div>
</div> </div>
</template> </template>

View File

@ -289,7 +289,10 @@ const en = {
follow_import: 'Follow import', follow_import: 'Follow import',
import_followers_from_a_csv_file: 'Import follows from a csv file', import_followers_from_a_csv_file: 'Import follows from a csv file',
follows_imported: 'Follows imported! Processing them will take a while.', 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 asked to download your file',
follow_export_button: 'Export your follows to a csv file'
}, },
notifications: { notifications: {
notifications: 'Notifications', notifications: 'Notifications',