diff --git a/appinfo/routes.php b/appinfo/routes.php index ab7d9152..37fb1fbe 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -78,6 +78,7 @@ return [ #Icons + ['name' => 'icon#getSingleIcon', 'url' => '/api/v2/geticon/{base64Url}', 'verb' => 'GET'], ['name' => 'icon#getIcon', 'url' => '/api/v2/icon/{base64Url}', 'verb' => 'GET'], ['name' => 'icon#getIcon', 'url' => '/api/v2/icon/{base64Url}/{credentialId}', 'verb' => 'GET'], ['name' => 'icon#getLocalIconList', 'url' => '/api/v2/icon/list', 'verb' => 'GET'], diff --git a/controller/iconcontroller.php b/controller/iconcontroller.php index 792b7742..97a24813 100644 --- a/controller/iconcontroller.php +++ b/controller/iconcontroller.php @@ -52,6 +52,28 @@ class IconController extends ApiController { } + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function getSingleIcon($base64Url) { + $url = base64_decode(str_replace('_','/', $base64Url)); + if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { + $url = "http://" . $url; + } + + + $icon = new IconService($url); + + if ($icon->icoExists) { + $icon_json['type']= $icon->icoType; + $icon_json['content']= base64_encode($icon->icoData); + return new JSONResponse($icon_json); + } + + return new JSONResponse(); + } + /** * @NoAdminRequired * @NoCSRFRequired diff --git a/controller/translationcontroller.php b/controller/translationcontroller.php index 3561dd58..a5deb2e6 100644 --- a/controller/translationcontroller.php +++ b/controller/translationcontroller.php @@ -143,6 +143,10 @@ class TranslationController extends ApiController { 'pick.icon.search' => $this->trans->t('Search icons'), 'pick.icon.custom.label' => $this->trans->t('Upload a custom icon:'), 'use.icon' => $this->trans->t('Use this icon'), + 'use.icon.delete' => $this->trans->t('Delete current icon'), + 'use.icon.refresh' => $this->trans->t('Get icon from page'), + 'use.icon.refresh.trying' => $this->trans->t('This may take a few seconds...'), + 'use.icon.refresh.error' => $this->trans->t('There was an error fetching the icon!'), 'selected.icon' => $this->trans->t('Selected icon'), // templates/views/partials/edit_credential/custom_fields.html diff --git a/js/app/controllers/edit_credential.js b/js/app/controllers/edit_credential.js index 40842a4a..aa99bf14 100644 --- a/js/app/controllers/edit_credential.js +++ b/js/app/controllers/edit_credential.js @@ -370,19 +370,6 @@ $scope.updateExistingListWithCredential(updated_cred); }); } - $scope.refreshListWithSaved(); - }; - - $scope.refreshListWithSaved = function () { - var current_vault = $rootScope.vaultCache[$scope.active_vault.guid]; - var cv_credentials = current_vault.credentials; - for (var i = 0; i < cv_credentials.length; i++) { - if (cv_credentials[i].credential_id === $scope.storedCredential.credential_id) { - cv_credentials[i] = $scope.storedCredential; - } - } - current_vault.credentials=cv_credentials; - $rootScope.vaultCache[$scope.active_vault.guid] = current_vault; }; $scope.updateExistingListWithCredential = function (credential) { @@ -395,14 +382,13 @@ } credential.tags_raw = credential.tags; - var found=false; var credList=$rootScope.vaultCache[$scope.active_vault.guid].credentials; for (var i = 0; i < credList.length; i++) { - if (credList[i].credential_id === credential.credential_id) { + if (credList[i].credential_id === credential.credential_id) { $rootScope.vaultCache[$scope.active_vault.guid].credentials[i]=credential; found=true; - } + } } if(!found){ diff --git a/js/app/directives/iconpicker.js b/js/app/directives/iconpicker.js index 706b18ea..dda10fdb 100644 --- a/js/app/directives/iconpicker.js +++ b/js/app/directives/iconpicker.js @@ -30,7 +30,7 @@ * # passwordGen */ angular.module('passmanApp').directive('iconPicker', [ - '$window', 'IconService', '$http', function($window, IconService, $http) { + '$window', 'IconService', '$http', 'NotificationService','$translate', function($window, IconService, $http, NotificationService, $translate) { return { templateUrl: 'views/partials/icon-picker.html', restrict: 'A', @@ -95,8 +95,6 @@ }; $('#iconPicker-CustomIcon').on('change', function(ev) { - - console.log("upload"); scope.customIcon = {}; var f = ev.target.files[0]; @@ -110,26 +108,44 @@ fr.readAsDataURL(f); }); + scope.deleteIcon = function() { + delete scope.credential.icon.type; + delete scope.credential.icon.content; + delete scope.credential.icon; + $('#iconPicker').dialog('close'); + }; + + scope.refreshUrlIcon = function(){ + NotificationService.showNotification($translate.instant('use.icon.refresh.trying'), 5000); + var queryUrl = OC.generateUrl('apps/passman/api/v2/geticon/'+btoa(scope.credential.url)); + $http.get(queryUrl).then(function (response) { + if(typeof response.data.content !== 'undefined'){ + scope.customIcon = {}; + scope.customIcon.data='data:image/'+response.data.type+';base64,'+response.data.content; + }else{ + NotificationService.showNotification($translate.instant('use.icon.refresh.error'), 5000); + } + }); + }; + scope.useIcon = function() { if(scope.customIcon){ var data = scope.customIcon.data; scope.credential.icon.type = data.substring(data.lastIndexOf(":")+1,data.lastIndexOf(";")); scope.credential.icon.content = data.substring(data.lastIndexOf(",")+1, data.length); - $('#iconPicker').dialog('close'); - return; + }else{ + $http.get(scope.selectedIcon.url).then(function(result) { + var base64Data = window.btoa(result.data); + var mimeType = 'svg+xml'; + if(!scope.credential.icon){ + scope.credential.icon = {}; + } + scope.credential.icon.type = mimeType; + scope.credential.icon.content = base64Data; + }); } - - $http.get(scope.selectedIcon.url).then(function(result) { - var base64Data = window.btoa(result.data); - var mimeType = 'svg+xml'; - if(!scope.credential.icon){ - scope.credential.icon = {}; - } - scope.credential.icon.type = mimeType; - scope.credential.icon.content = base64Data; - $('#iconPicker').dialog('close'); - }); + $('#iconPicker').dialog('close'); }; $(element).click(function() { diff --git a/sass/credentials.scss b/sass/credentials.scss index d6d7b1b7..8c883da8 100644 --- a/sass/credentials.scss +++ b/sass/credentials.scss @@ -696,8 +696,11 @@ .icon-label { overflow: hidden; + display: flex; input { - width: calc(100% - 28px) !important; + //width: calc(100% - 28px) !important; + //width: 100% !important; + //width: inherit !important; float: left; background: #fff; color: #555; diff --git a/templates/views/partials/icon-picker.html b/templates/views/partials/icon-picker.html index 22928f8a..318c0fe4 100644 --- a/templates/views/partials/icon-picker.html +++ b/templates/views/partials/icon-picker.html @@ -1,6 +1,13 @@ -
+ + +