Skip to content

Commit 19d781f

Browse files
authoredSep 21, 2020
Replace JS package toggle w/ pure CSS solution (apache#11035)
1 parent 17faea0 commit 19d781f

File tree

9 files changed

+98
-40
lines changed

9 files changed

+98
-40
lines changed
 

‎.rat-excludes

-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ underscore.js
6464
jquery.dataTables.min.js
6565
jqClock.min.js
6666
dagre-d3.min.js
67-
bootstrap-toggle.min.js
68-
bootstrap-toggle.min.css
6967
d3.v3.min.js
7068
ace.js
7169
node_modules/*

‎airflow/www/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
},
6161
"dependencies": {
6262
"bootstrap-3-typeahead": "^4.0.2",
63-
"bootstrap-toggle": "^2.2.2",
6463
"d3": "^3.4.4",
6564
"d3-tip": "^0.9.1",
6665
"dagre-d3": "^0.6.4",

‎airflow/www/static/css/switch.css

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
.switch-label {
21+
display: inline-block;
22+
margin: 0;
23+
cursor: pointer;
24+
}
25+
26+
.switch-input {
27+
/* Visusally hidden input but still accessible */
28+
position: absolute;
29+
overflow: hidden;
30+
clip: rect(1px, 1px, 1px, 1px);
31+
border: 0;
32+
width: 1px;
33+
height: 1px;
34+
padding: 0;
35+
white-space: nowrap;
36+
clip-path: inset(50%);
37+
}
38+
39+
.switch {
40+
box-sizing: content-box;
41+
display: inline-flex;
42+
align-items: center;
43+
border-radius: 999px;
44+
width: 2.5rem;
45+
padding: 2px;
46+
background-color: #c4c2c1;
47+
cursor: pointer;
48+
}
49+
50+
.switch::before {
51+
border-radius: 50%;
52+
width: 1.5rem;
53+
height: 1.5rem;
54+
content: '';
55+
background-color: #edecec;
56+
transition-timing-function: ease-in-out;
57+
transition-duration: 0.25s;
58+
transition-property: transform, background-color;
59+
}
60+
61+
.switch-input:checked + .switch {
62+
background-color: #005c66;
63+
}
64+
65+
.switch-input:checked + .switch::before {
66+
background-color: #fffefd;
67+
transform: translateX(1rem);
68+
}
69+
70+
.switch-input:focus + .switch {
71+
box-shadow: 0 0 0 3px rgba(0, 92, 102, 0.4);
72+
}
73+
74+
.switch-input:focus + .switch::before {
75+
background-color: #fff;
76+
}
77+
78+
.switch-input:not(:checked) + .switch:hover {
79+
background-color: #9e9e9c;
80+
}
81+
82+
.switch-input:not(:checked) + .switch:hover::before {
83+
background-color: #f5f5f5;
84+
}

‎airflow/www/templates/airflow/dag.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
{% block head_css %}
2525
{{ super() }}
26-
<link href="{{ url_for_asset('bootstrap-toggle.min.css') }}" rel="stylesheet" type="text/css">
26+
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/switch.css') }}">
2727
{% endblock %}
2828

2929
{% block content %}
@@ -32,7 +32,10 @@ <h3 class="pull-left">
3232
{% if dag.parent_dag is defined and dag.parent_dag %}
3333
<span class="text-muted">SUBDAG:</span> {{ dag.dag_id }}
3434
{% else %}
35-
<input id="pause_resume" dag_id="{{ dag.dag_id }}" type="checkbox" {{ "checked" if not dag.is_paused else "" }} data-toggle="toggle" data-size="mini" method="post">
35+
<label class="switch-label js-tooltip" title="Pause/Unpause DAG">
36+
<input class="switch-input" id="pause_resume" dag_id="{{ dag.dag_id }}" type="checkbox" {{ "checked" if not dag.is_paused else "" }} method="post">
37+
<span class="switch" aria-hidden="true"></span>
38+
</label>
3639
<span class="text-muted">DAG:</span> {{ dag.dag_id }}
3740
<small class="text-muted">{{ dag.description[0:150] + '…' if dag.description and dag.description|length > 150 else dag.description|default('', true) }}</small>
3841
{% endif %}
@@ -343,7 +346,6 @@ <h4 class="modal-title" id="dagModalLabel">
343346
{% endblock %}
344347
{% block tail %}
345348
{{ super() }}
346-
<script src="{{ url_for_asset('bootstrap-toggle.min.js') }}"></script>
347349
<script>
348350
function updateQueryStringParameter(uri, key, value) {
349351
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
@@ -595,5 +597,6 @@ <h4 class="modal-title" id="dagModalLabel">
595597
$buttons.addClass('btn-danger');
596598
});
597599
});
600+
$('.js-tooltip').tooltip();
598601
</script>
599602
{% endblock %}

‎airflow/www/templates/airflow/dags.html

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
{% block head_css %}
3131
{{ super() }}
32-
<link href="{{ url_for_asset('dataTables.bootstrap.min.css') }}" rel="stylesheet" type="text/css">
33-
<link href="{{ url_for_asset('bootstrap-toggle.min.css') }}" rel="stylesheet" type="text/css">
32+
<link rel="stylesheet" type="text/css" href="{{ url_for_asset('dataTables.bootstrap.min.css') }}">
33+
<link rel="stylesheet" type="text/css" href="{{ url_for_asset('switch.css') }}">
3434
{% endblock %}
3535

3636
{% block content %}
@@ -102,7 +102,10 @@ <h2>DAGs</h2>
102102

103103
<!-- Column 2: Turn dag on/off -->
104104
<td>
105-
<input id="toggle-{{ dag.dag_id }}" dag_id="{{ dag.dag_id }}" type="checkbox" {{ "checked" if not dag.is_paused else "" }} data-toggle="toggle" data-size="mini" method="post">
105+
<label class="switch-label js-tooltip" title="Pause/Unpause DAG">
106+
<input class="switch-input" id="toggle-{{ dag.dag_id }}" dag_id="{{ dag.dag_id }}" type="checkbox" {{ "checked" if not dag.is_paused else "" }} method="post">
107+
<span class="switch" aria-hidden="true"></span>
108+
</label>
106109
</td>
107110

108111
<!-- Column 3: Name -->
@@ -245,7 +248,6 @@ <h2>DAGs</h2>
245248
<script src="{{ url_for_asset('d3.min.js') }}"></script>
246249
<script src="{{ url_for_asset('jquery.dataTables.min.js') }}"></script>
247250
<script src="{{ url_for_asset('dataTables.bootstrap.min.js') }}"></script>
248-
<script src="{{ url_for_asset('bootstrap-toggle.min.js') }}"></script>
249251
<script>
250252

251253
const DAGS_INDEX = "{{ url_for('Airflow.index') }}";
@@ -593,5 +595,6 @@ <h2>DAGs</h2>
593595
hideSvgTooltip();
594596
});
595597
});
598+
$('.js-tooltip').tooltip();
596599
</script>
597600
{% endblock %}

‎airflow/www/webpack.config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ const config = {
4040
'task-instances': `${STATIC_DIR}/js/task-instances.js`,
4141
ganttChartD3v2: `${STATIC_DIR}/js/gantt-chart-d3v2.js`,
4242
main: `${STATIC_DIR}/css/main.css`,
43+
switch: `${STATIC_DIR}/css/switch.css`,
4344
airflowDefaultTheme: `${STATIC_DIR}/css/bootstrap-theme.css`,
4445
moment: 'moment-timezone',
4546
},
@@ -145,9 +146,6 @@ const config = {
145146
}, {
146147
from: 'node_modules/bootstrap-3-typeahead/*min.*',
147148
flatten: true
148-
}, {
149-
from: 'node_modules/bootstrap-toggle/**/*bootstrap-toggle.min.*',
150-
flatten: true,
151149
}, {
152150
from: 'node_modules/datatables.net/**/**.min.*',
153151
flatten: true

‎airflow/www/yarn.lock

-5
Original file line numberDiff line numberDiff line change
@@ -1161,11 +1161,6 @@ bootstrap-3-typeahead@^4.0.2:
11611161
resolved "https://registry.yarnpkg.com/bootstrap-3-typeahead/-/bootstrap-3-typeahead-4.0.2.tgz#cb1c969044856862096fc8c71cc21b3acbb50412"
11621162
integrity sha1-yxyWkESFaGIJb8jHHMIbOsu1BBI=
11631163

1164-
bootstrap-toggle@^2.2.2:
1165-
version "2.2.2"
1166-
resolved "https://registry.yarnpkg.com/bootstrap-toggle/-/bootstrap-toggle-2.2.2.tgz#2b88534fc1b998674f877f98ba0d8b5b743e96fe"
1167-
integrity sha1-K4hTT8G5mGdPh3+Yug2LW3Q+lv4=
1168-
11691164
bootstrap@^3.3:
11701165
version "3.4.1"
11711166
resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-3.4.1.tgz#c3a347d419e289ad11f4033e3c4132b87c081d72"

‎licenses/LICENSE-bootstrap-toggle.txt

-21
This file was deleted.

‎setup.cfg

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ license_files =
2626
LICENSE
2727
NOTICE
2828
# Start of licenses generated automatically
29-
licenses/LICENSE-bootstrap-toggle.txt
3029
licenses/LICENSE-bootstrap.txt
3130
licenses/LICENSE-bootstrap3-typeahead.txt
3231
licenses/LICENSE-d3-tip.txt

0 commit comments

Comments
 (0)
Please sign in to comment.