forked from dart-archive/angular.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.dart
More file actions
141 lines (126 loc) · 3.45 KB
/
Copy pathform.dart
File metadata and controls
141 lines (126 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import 'package:angular/angular.dart';
import 'package:angular/application_factory.dart';
@Component(
selector: '[form-controller]',
templateUrl: 'form_controller.html',
useShadowDom: false)
class FormCtrl {
static const String _COLOR_HEX = "hex";
static const String _COLOR_HSL = "hsl";
static const String _COLOR_RGB = "rgb";
static const String _COLOR_NAME = "name";
static const _COLOR_TYPES = const [_COLOR_RGB, _COLOR_HSL, _COLOR_HEX, _COLOR_NAME];
static const _RESOLUTIONS = const ['1024x600',
'1280x800',
'1366x768',
'1440x900',
'1600x900',
'1680x1050',
'1920x1080',
'1920x1200',
'2560x1440',
'2560x1600'];
Scope scope;
final List colors = [];
final List formattedColors = [];
NgForm myForm;
NgForm colorForm;
NgForm colorsForm;
Map info;
PreviewCtrl preview;
FormCtrl() {
newColor(_COLOR_HEX, '#222');
newColor(_COLOR_HEX, '#444');
newColor(_COLOR_HEX, '#000');
info = new Map();
}
List<String> get colorTypes => _COLOR_TYPES;
List<String> get resolutions => _RESOLUTIONS;
void submit() {
myForm.reset();
}
int getTotalSquares(inputValue) {
var value = 4;
if(inputValue != null) {
try {
value = double.parse(inputValue.toString());
} catch(e) {
}
}
return (value * value).toInt();
}
List<String> formatColors() {
formattedColors.clear();
colors.forEach((color) {
var value = null;
switch(color['type']) {
case _COLOR_HEX:
value = color['hex'];
break;
case _COLOR_HSL:
var hue = color['hue'];
var saturation = color['saturation'];
var luminance = color['luminance'];
if(hue != null && saturation != null && luminance != null) {
value = "hsl($hue, $saturation%, $luminance%)";
}
break;
case _COLOR_RGB:
var red = color['red'];
var blue = color['blue'];
var green = color['green'];
if(red != null && green != null && blue != null) {
value = "rgb($red, $green, $blue)";
}
break;
default: //COLOR_NAME
value = color['name'];
break;
}
if(value != null) {
formattedColors.add(value);
}
});
return formattedColors;
}
void newColor([String type = _COLOR_HEX, String color]) {
colors.add({
'id' : colors.length,
'type' : type,
'hex' : type == _COLOR_HEX ? color : '',
'hue' : '',
'saturation' : '',
'luminance' : '',
'red' : '',
'green' : '',
'blue': '',
'name': ''
});
}
}
@Decorator(
selector: '[preview-controller]'
)
class PreviewCtrl {
PreviewCtrl(FormCtrl form) {
form.preview = this;
}
List _collection = [];
List expandList(items, limit) {
_collection.clear();
if(items != null && items.length > 0) {
for (var i = 0; i < limit; i++) {
var x = i % items.length;
_collection.add(items[x]);
}
}
return _collection;
}
}
main() {
applicationFactory()
..addModule(new Module()
..bind(FormCtrl)
..bind(PreviewCtrl))
..run();
}