GUI Rework: reorganized folders and split app.js
This commit is contained in:
committed by
Jakob Borg
parent
8588625937
commit
3b88ee623b
65
gui/scripts/syncthing/core/directives/identiconDirective.js
Normal file
65
gui/scripts/syncthing/core/directives/identiconDirective.js
Normal file
@@ -0,0 +1,65 @@
|
||||
angular.module('syncthing.core')
|
||||
.directive('identicon', ['$window', function ($window) {
|
||||
var svgNS = 'http://www.w3.org/2000/svg';
|
||||
|
||||
function Identicon(value, size) {
|
||||
var svg = document.createElementNS(svgNS, 'svg');
|
||||
var shouldFillRectAt = function (row, col) {
|
||||
return !($window.parseInt(value.charCodeAt(row + col * size), 10) % 2);
|
||||
};
|
||||
var shouldMirrorRectAt = function (row, col) {
|
||||
return !(size % 2 && col === middleCol)
|
||||
};
|
||||
var mirrorColFor = function (col) {
|
||||
return size - col - 1;
|
||||
};
|
||||
var fillRectAt = function (row, col) {
|
||||
var rect = document.createElementNS(svgNS, 'rect');
|
||||
|
||||
rect.setAttribute('x', (col * rectSize) + '%');
|
||||
rect.setAttribute('y', (row * rectSize) + '%');
|
||||
rect.setAttribute('width', rectSize + '%');
|
||||
rect.setAttribute('height', rectSize + '%');
|
||||
|
||||
svg.appendChild(rect);
|
||||
};
|
||||
var rect;
|
||||
var row;
|
||||
var col;
|
||||
var middleCol;
|
||||
var rectSize;
|
||||
|
||||
svg.setAttribute('class', 'identicon');
|
||||
size = size || 5;
|
||||
rectSize = 100 / size;
|
||||
middleCol = Math.ceil(size / 2) - 1;
|
||||
|
||||
if (value) {
|
||||
value = value.toString().replace(/[\W_]/i, '');
|
||||
|
||||
for (row = 0; row < size; ++row) {
|
||||
for (col = middleCol; col > -1; --col) {
|
||||
if (shouldFillRectAt(row, col)) {
|
||||
fillRectAt(row, col);
|
||||
|
||||
if (shouldMirrorRectAt(row, col)) {
|
||||
fillRectAt(row, mirrorColFor(col));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return svg;
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: 'E',
|
||||
scope: {
|
||||
value: '='
|
||||
},
|
||||
link: function (scope, element, attributes) {
|
||||
element.append(new Identicon(scope.value));
|
||||
}
|
||||
}
|
||||
}]);
|
||||
16
gui/scripts/syncthing/core/directives/modalDirective.js
Normal file
16
gui/scripts/syncthing/core/directives/modalDirective.js
Normal file
@@ -0,0 +1,16 @@
|
||||
angular.module('syncthing.core')
|
||||
.directive('modal', function () {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: 'modal.html',
|
||||
replace: true,
|
||||
transclude: true,
|
||||
scope: {
|
||||
title: '@',
|
||||
status: '@',
|
||||
icon: '@',
|
||||
close: '@',
|
||||
large: '@'
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
angular.module('syncthing.core')
|
||||
.directive('uniqueFolder', function () {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function (scope, elm, attrs, ctrl) {
|
||||
ctrl.$parsers.unshift(function (viewValue) {
|
||||
if (scope.editingExisting) {
|
||||
// we shouldn't validate
|
||||
ctrl.$setValidity('uniqueFolder', true);
|
||||
} else if (scope.folders[viewValue]) {
|
||||
// the folder exists already
|
||||
ctrl.$setValidity('uniqueFolder', false);
|
||||
} else {
|
||||
// the folder is unique
|
||||
ctrl.$setValidity('uniqueFolder', true);
|
||||
}
|
||||
return viewValue;
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
angular.module('syncthing.core')
|
||||
.directive('validDeviceid', function ($http) {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function (scope, elm, attrs, ctrl) {
|
||||
ctrl.$parsers.unshift(function (viewValue) {
|
||||
if (scope.editingExisting) {
|
||||
// we shouldn't validate
|
||||
ctrl.$setValidity('validDeviceid', true);
|
||||
} else {
|
||||
$http.get(urlbase + '/deviceid?id=' + viewValue).success(function (resp) {
|
||||
if (resp.error) {
|
||||
ctrl.$setValidity('validDeviceid', false);
|
||||
} else {
|
||||
ctrl.$setValidity('validDeviceid', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
return viewValue;
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user