forked from academiadocodigo/TBGWebCharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Generic.ProgressBar.pas
141 lines (120 loc) · 3.28 KB
/
Generic.ProgressBar.pas
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
unit Generic.ProgressBar;
interface
uses
Interfaces, Colors.Bootstrap;
Type
TModelGenericProgressBar<T : IInterface> = class(TInterfacedObject, iModelGenericProgressBar<T>)
private
[weak]
FParent : T;
FBackground : string;
FColor : string;
FDisplayLabel : Boolean;
FHeight : string;
FHTML : String;
FStyle : string;
FValue : string;
procedure GenerateHTML;
public
constructor Create(Parent : T);
destructor Destroy; override;
class function New(Parent : T) : iModelGenericProgressBar<T>;
function Background(aValue : string) : iModelGenericProgressBar<T>;
function Color(aValue : string) : iModelGenericProgressBar<T>;
function DisplayLabel(aValue : Boolean) : iModelGenericProgressBar<T>;
function Height(aValue : Integer) : iModelGenericProgressBar<T>; overload;
function Height : string; overload;
function HTML : String;
function Sytle(aValue : TTypeBackgroundColor) : iModelGenericProgressBar<T>;
function Value(aValue : string) : iModelGenericProgressBar<T>;
function &End : T;
end;
implementation
uses
Injection,
Utilities.Str,
System.SysUtils;
{ TModelProgress<T> }
function TModelGenericProgressBar<T>.&End: T;
begin
Result := FParent;
end;
procedure TModelGenericProgressBar<T>.GenerateHTML;
var
LLabel : string;
begin
LLabel := '';
if FDisplayLabel then
LLabel := FValue + '%';
FHTML :=
'<div ' +
'class="progress-bar' + FStyle + ' "' +
'role="progressbar" ' +
'data-width="' + FValue + '%" ' +
'aria-valuenow="' + FValue + '" ' +
'aria-valuemin="0" aria-valuemax="100" ' +
'style="width: ' + FValue + '%;' + FBackground + FColor + '"' +
'>' + LLAbel + '</div>';
end;
function TModelGenericProgressBar<T>.Background(
aValue: string): iModelGenericProgressBar<T>;
begin
Result := Self;
FBackground := Format('background: %s;', [aValue]);
end;
function TModelGenericProgressBar<T>.Color(
aValue: string): iModelGenericProgressBar<T>;
begin
Result := Self;
FColor := Format('color: %s;', [TUtilitiesStr.TestRgbColor(aValue)]);
end;
constructor TModelGenericProgressBar<T>.Create(Parent : T);
begin
{$IF RTLVERSION > 27 }
TInjection.Weak(@FParent, Parent);
{$ELSE}
FParent := Parent;
{$IFEND}
end;
destructor TModelGenericProgressBar<T>.Destroy;
begin
inherited;
end;
function TModelGenericProgressBar<T>.DisplayLabel(
aValue: Boolean): iModelGenericProgressBar<T>;
begin
Result := Self;
FDisplayLabel := aValue;
end;
function TModelGenericProgressBar<T>.Height(
aValue: Integer): iModelGenericProgressBar<T>;
begin
Result := Self;
FHeight := Format(' style="height: %dpx;"', [aValue]);
end;
function TModelGenericProgressBar<T>.Height: string;
begin
Result := FHeight;
end;
function TModelGenericProgressBar<T>.HTML: String;
begin
GenerateHTML;
Result := FHTML;
end;
class function TModelGenericProgressBar<T>.New(Parent : T) : iModelGenericProgressBar<T>;
begin
Result := Self.Create(Parent);
end;
function TModelGenericProgressBar<T>.Sytle(
aValue: TTypeBackgroundColor): iModelGenericProgressBar<T>;
begin
Result := Self;
FStyle := Format(' %s',[aValue.ToString]);
end;
function TModelGenericProgressBar<T>.Value(
aValue: string): iModelGenericProgressBar<T>;
begin
Result := Self;
FValue := aValue;
end;
end.