From 912f9928fe4e3fce2d929d2a5cfcca4ff006f768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa?= Date: Wed, 16 May 2018 18:18:35 +0200 Subject: [PATCH] Dowload user profile --- app/coffee/modules/auth.coffee | 4 ++++ app/coffee/modules/resources.coffee | 1 + app/coffee/modules/user-settings/main.coffee | 15 ++++++++++++++- app/locales/taiga/locale-en.json | 1 + app/partials/user/user-profile.jade | 8 ++++++++ .../modules/user-settings/user-profile.scss | 15 ++++++++++++++- 6 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/coffee/modules/auth.coffee b/app/coffee/modules/auth.coffee index 1822a9db..82fa1876 100644 --- a/app/coffee/modules/auth.coffee +++ b/app/coffee/modules/auth.coffee @@ -234,6 +234,10 @@ class AuthService extends taiga.Service data = _.clone(data, false) return @http.post(url, data) + exportProfile: () -> + url = @urls.resolve("users-export") + return @http.post(url) + module.service("$tgAuth", AuthService) diff --git a/app/coffee/modules/resources.coffee b/app/coffee/modules/resources.coffee index 64d8a299..f596ef76 100644 --- a/app/coffee/modules/resources.coffee +++ b/app/coffee/modules/resources.coffee @@ -40,6 +40,7 @@ urls = { "users-change-password": "/users/change_password" "users-change-email": "/users/change_email" "users-cancel-account": "/users/cancel" + "users-export": "/users/export" "user-stats": "/users/%s/stats" "user-liked": "/users/%s/liked" "user-voted": "/users/%s/voted" diff --git a/app/coffee/modules/user-settings/main.coffee b/app/coffee/modules/user-settings/main.coffee index 7057eaaf..edd66f4a 100644 --- a/app/coffee/modules/user-settings/main.coffee +++ b/app/coffee/modules/user-settings/main.coffee @@ -47,10 +47,11 @@ class UserSettingsController extends mixOf(taiga.Controller, taiga.PageMixin) "$tgAuth", "$translate", "tgErrorHandlingService" + "$window" ] constructor: (@scope, @rootscope, @config, @repo, @confirm, @rs, @params, @q, @location, @navUrls, - @auth, @translate, @errorHandlingService) -> + @auth, @translate, @errorHandlingService, @window) -> @scope.sectionName = "USER_SETTINGS.MENU.SECTION_TITLE" @scope.project = {} @@ -90,6 +91,18 @@ class UserSettingsController extends mixOf(taiga.Controller, taiga.PageMixin) @config.get("defaultTheme") || "taiga" + exportProfile: -> + onSuccess = (result) -> + dumpUrl = result.data.url + @window.open(dumpUrl, "_blank") + + onError = (response) => + if response.data?._error_message + @confirm.notify("error", response.data._error_message) + + @auth.exportProfile().then(onSuccess, onError) + + module.controller("UserSettingsController", UserSettingsController) diff --git a/app/locales/taiga/locale-en.json b/app/locales/taiga/locale-en.json index cf525c24..6680bf55 100644 --- a/app/locales/taiga/locale-en.json +++ b/app/locales/taiga/locale-en.json @@ -1516,6 +1516,7 @@ "USER_PROFILE": { "ACTION_USE_GRAVATAR": "Use default image", "ACTION_DELETE_ACCOUNT": "Delete Taiga account", + "ACTION_DOWNLOAD_PROFILE": "Download Taiga profile", "CHANGE_EMAIL_SUCCESS": "Check your inbox!
We have sent a mail to your account
with the instructions to set your new address", "CHANGE_PHOTO": "Change photo", "FIELD": { diff --git a/app/partials/user/user-profile.jade b/app/partials/user/user-profile.jade index 39f345cc..48afe4ed 100644 --- a/app/partials/user/user-profile.jade +++ b/app/partials/user/user-profile.jade @@ -116,6 +116,14 @@ div.wrapper( title="{{'COMMON.SAVE' | translate}}", translate="COMMON.SAVE" ) + + div.actions + a.download-profile( + href="" + title="{{'USER_PROFILE.ACTION_DOWNLOAD_PROFILE' | translate}}" + ng-click="ctrl.exportProfile()" + translate="USER_PROFILE.ACTION_DOWNLOAD_PROFILE" + ) a.delete-account( href="" title="{{'USER_PROFILE.ACTION_DELETE_ACCOUNT' | translate}}" diff --git a/app/styles/modules/user-settings/user-profile.scss b/app/styles/modules/user-settings/user-profile.scss index 97d554eb..0dc5ac8f 100644 --- a/app/styles/modules/user-settings/user-profile.scss +++ b/app/styles/modules/user-settings/user-profile.scss @@ -6,9 +6,22 @@ .submit-button { width: 100%; } + + .actions { + align-items: center; + display: flex; + justify-content: center; + margin-top: .5rem; + } + + .download-profile, .delete-account { @include font-size(small); display: block; - margin-top: 1rem; + flex: 1; + margin-top: .5rem; + } + .delete-account { + text-align: right; } }