From 825455ea6c08862874255bff43c2cd047fc3a509 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 5 Jan 2015 17:10:01 -0500 Subject: [PATCH] Get the contacts field partially working --- static/css/quay.css | 4 + .../config/config-contact-field.html | 44 +++++ .../config/config-contacts-field.html | 4 + .../directives/config/config-setup-tool.html | 13 +- static/js/core-config-setup.js | 153 ++++++++++++++---- 5 files changed, 176 insertions(+), 42 deletions(-) create mode 100644 static/directives/config/config-contact-field.html create mode 100644 static/directives/config/config-contacts-field.html diff --git a/static/css/quay.css b/static/css/quay.css index 87605cede..e3aced015 100644 --- a/static/css/quay.css +++ b/static/css/quay.css @@ -4923,4 +4923,8 @@ i.slack-icon { border: 1px solid #eee; vertical-align: middle; padding: 4px; +} + +.config-contact-field .form-control { + width: 350px; } \ No newline at end of file diff --git a/static/directives/config/config-contact-field.html b/static/directives/config/config-contact-field.html new file mode 100644 index 000000000..f1b98a4c1 --- /dev/null +++ b/static/directives/config/config-contact-field.html @@ -0,0 +1,44 @@ +
+ + + + + +
+ + + +
+
\ No newline at end of file diff --git a/static/directives/config/config-contacts-field.html b/static/directives/config/config-contacts-field.html new file mode 100644 index 000000000..c658867c8 --- /dev/null +++ b/static/directives/config/config-contacts-field.html @@ -0,0 +1,4 @@ +
+
+
+
\ No newline at end of file diff --git a/static/directives/config/config-setup-tool.html b/static/directives/config/config-setup-tool.html index 1eed02743..979a6b3bd 100644 --- a/static/directives/config/config-setup-tool.html +++ b/static/directives/config/config-setup-tool.html @@ -24,22 +24,11 @@ Contact Information: - +
Information to show in the Contact Page. If none specified, CoreOS contact information is displayed.
- -
- - - - - - -
E-mailmailto:some@email.com
IRCirc://server:port/channel
Telephonetel:number
Twitterhttps://twitter.com/twitterhandle
URLhttp(s)://*
-
diff --git a/static/js/core-config-setup.js b/static/js/core-config-setup.js index a42cf9f88..1aff16ea9 100644 --- a/static/js/core-config-setup.js +++ b/static/js/core-config-setup.js @@ -13,35 +13,6 @@ angular.module("core-config-setup", ['angularFileUpload']) $scope.config = null; $scope.mapped = {}; - $scope.parseDbUri = function(value) { - if (!value) { return null; } - - // Format: mysql+pymysql://:@/ - var uri = URI(value); - return { - 'kind': uri.protocol(), - 'username': uri.username(), - 'password': uri.password(), - 'server': uri.hostname(), - 'port': uri.port(), - 'database': uri.path() ? uri.path().substr(1) : '' - }; - }; - - $scope.serializeDbUri = function(fields) { - if (!fields['server']) { return '' }; - - var uri = URI(); - uri = uri && uri.hostname(fields['server']); - uri = uri && uri.protocol(fields['kind']); - uri = uri && uri.username(fields['username']); - uri = uri && uri.password(fields['password']); - uri = uri && uri.port(fields['port']); - uri = uri && uri.path('/' + (fields['database'] || '')); - uri = uri && uri.toString(); - return uri; - }; - var githubSelector = function(key) { return function(value) { if (!value || !$scope.config) { return; } @@ -116,7 +87,6 @@ angular.module("core-config-setup", ['angularFileUpload']) $scope.$watch('mapped.redis.password', redisSetter('password')); $scope.$watch('config', function(value) { - window.console.log(value); }, true); $scope.$watch('isActive', function(value) { @@ -394,6 +364,129 @@ angular.module("core-config-setup", ['angularFileUpload']) return directiveDefinitionObject; }) + .directive('configContactsField', function () { + var directiveDefinitionObject = { + priority: 0, + templateUrl: '/static/directives/config/config-contacts-field.html', + priority: 1, + replace: false, + transclude: false, + restrict: 'C', + scope: { + 'binding': '=binding' + }, + controller: function($scope, $element) { + $scope.$watch('items', function(items) { + if (!items) { return; } + + // Remove the last item if both it and the second to last items are empty. + if (items.length > 1 && !items[items.length - 2].value && !items[items.length - 1].value) { + items.splice(items.length - 1, 1); + return; + } + + // If the last item is non-empty, add a new item. + if (items[items.length - 1].value) { + items.push({'value': ''}); + } + }, true); + + $scope.$watch('binding', function(binding) { + $scope.items = []; + $scope.items.push({'value': ''}); + }); + } + }; + return directiveDefinitionObject; + }) + + .directive('configContactField', function () { + var directiveDefinitionObject = { + priority: 0, + templateUrl: '/static/directives/config/config-contact-field.html', + priority: 1, + replace: false, + transclude: true, + restrict: 'C', + scope: { + 'binding': '=binding' + }, + controller: function($scope, $element) { + $scope.kind = null; + $scope.value = null; + + var updateBinding = function() { + var value = $scope.value || ''; + + switch ($scope.kind) { + case 'mailto': + $scope.binding = 'mailto:' + value; + return; + + case 'tel': + $scope.binding = 'tel:' + value; + return; + + case 'irc': + $scope.binding = 'irc://' + value; + return; + + default: + $scope.binding = value; + return; + } + }; + + $scope.$watch('kind', updateBinding); + $scope.$watch('value', updateBinding); + + $scope.$watch('binding', function(value) { + if (!value) { + $scope.kind = null; + $scope.value = null; + return; + } + + var uri = URI(value); + $scope.kind = uri.scheme(); + + switch ($scope.kind) { + case 'mailto': + case 'tel': + $scope.value = uri.path(); + break; + + case 'irc': + $scope.value = value.substr('irc://'.length); + break; + + default: + $scope.kind = 'http'; + $scope.value = value; + break; + } + }); + + $scope.getPlaceholder = function(kind) { + switch (kind) { + case 'mailto': + return 'some@example.com'; + + case 'tel': + return '555-555-5555'; + + case 'irc': + return 'myserver:port/somechannel'; + + default: + return 'http://some/url'; + } + }; + } + }; + return directiveDefinitionObject; + }) + .directive('configStringField', function () { var directiveDefinitionObject = { priority: 0,