Skip to content

Commit c3fa2c9

Browse files
committed
feat(dockerfile): create dockerfile dialog with styled content
1 parent b327851 commit c3fa2c9

File tree

2 files changed

+116
-16
lines changed

2 files changed

+116
-16
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<!--
2+
Copyright (C) 2016-2023 Jones Magloire @Joxit
3+
4+
This program is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Affero General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Affero General Public License for more details.
13+
14+
You should have received a copy of the GNU Affero General Public License
15+
along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
-->
17+
<dockerfile>
18+
<material-popup opened="{ props.opened }" onClick="{ props.onClose }">
19+
<div class="material-popup-title">Dockerfile</div>
20+
<div class="material-popup-content">
21+
<template each="{ (_, idx) in props.elements }">
22+
<template
23+
each="{ element in props.elements[props.elements.length - 1 - idx].filter(e => e.key === 'created_by') }"
24+
>
25+
<div class="instruction">
26+
<span class="keyword">{ element.value }</span>
27+
<span>{ ' ' + element.content }</span>
28+
</div>
29+
</template>
30+
</template>
31+
</div>
32+
<div class="material-popup-action">
33+
<material-button
34+
class="dialog-button"
35+
waves-color="rgba(158,158,158,.4)"
36+
onClick="{ props.onClose }"
37+
color="inherit"
38+
text-color="var(--primary-text)"
39+
>
40+
Close
41+
</material-button>
42+
</div>
43+
</material-popup>
44+
<style>
45+
:host material-popup .popup material-button {
46+
margin-right: 1em;
47+
}
48+
:host material-popup .popup > .content {
49+
max-width: 75em;
50+
width: 80%;
51+
}
52+
:host .material-popup-content {
53+
background-color: var(--hover-background);
54+
}
55+
@media screen and (max-width: 800px) {
56+
:host material-popup .popup > .content {
57+
width: 100%;
58+
}
59+
}
60+
:host .instruction {
61+
font-family: 'Roboto Mono', monospace !important;
62+
margin: 0.75em 0;
63+
}
64+
:host .instruction .keyword {
65+
color: var(--accent-text);
66+
}
67+
</style>
68+
</dockerfile>

src/components/tag-history/tag-history.riot

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3636
waves-center="true"
3737
rounded="true"
3838
outlined
39+
onClick="{ showDockerfile }"
3940
>
4041
Dockerfile
4142
</material-button>
@@ -44,6 +45,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
4445
<div if="{ !state.loadend }" class="spinner-wrapper">
4546
<material-spinner></material-spinner>
4647
</div>
48+
<dockerfile
49+
opened="{ state.showDockerfile }"
50+
on-close="{ onDockerfileClose }"
51+
elements="{ state.elements }"
52+
></dockerfile>
4753

4854
<material-tabs
4955
if="{ state.archs && state.loadend }"
@@ -67,11 +73,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
6773
<script>
6874
import { DockerImage } from '../../scripts/docker-image';
6975
import { bytesToSize } from '../../scripts/utils';
76+
import Dockerfile from '../dialogs/dockerfile.riot';
7077
import router from '../../scripts/router';
7178
import TagHistoryElement from './tag-history-element.riot';
7279
export default {
7380
components: {
7481
TagHistoryElement,
82+
Dockerfile,
7583
},
7684
onBeforeMount(props, state) {
7785
state.elements = [];
@@ -115,10 +123,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
115123
for (var attribute in elt) {
116124
if (elt.hasOwnProperty(attribute) && attribute != 'empty_layer') {
117125
const value = elt[attribute];
118-
const guiElement = {
119-
'key': attribute,
120-
'value': modifySpecificAttributeTypes(attribute, value),
121-
};
126+
const guiElement = modifySpecificAttributeTypes(attribute, value);
122127
guiElements.push(guiElement);
123128
}
124129
}
@@ -153,6 +158,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
153158
toTaglist() {
154159
return router.taglist(this.props.image);
155160
},
161+
showDockerfile() {
162+
console.log(this);
163+
this.update({ showDockerfile: true });
164+
},
165+
onDockerfileClose() {
166+
this.update({ showDockerfile: false });
167+
},
156168
};
157169
const eltIdx = function (e) {
158170
switch (e) {
@@ -181,27 +193,47 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
181193
return eltIdx(e1.key) - eltIdx(e2.key);
182194
};
183195
184-
const modifySpecificAttributeTypes = function (attribute, value) {
185-
switch (attribute) {
196+
const parseCreatedBy = (value) => {
197+
if (value.startsWith('COPY')) {
198+
return {
199+
value: 'COPY',
200+
content: value.replace(/^COPY /, ''),
201+
};
202+
}
203+
let cmd = value.match(/\/bin\/sh *-c *#\(nop\) *([A-Z]+) (.*)/);
204+
return {
205+
value: (cmd && cmd[1]) || 'RUN',
206+
content: (cmd && cmd[2]) || value.replace(/^\/bin\/sh *-c *(#\(nop\))?/, ''),
207+
};
208+
};
209+
210+
const modifySpecificAttributeTypes = function (key, value) {
211+
switch (key) {
186212
case 'created':
187-
return new Date(value).toLocaleString();
213+
return { key, value: new Date(value).toLocaleString() };
188214
case 'created_by':
189-
const cmd = value.match(/\/bin\/sh *-c *#\(nop\) *([A-Z]+)/);
190-
return (cmd && cmd[1]) || 'RUN';
215+
const cmd = value.match(/\/bin\/sh *-c *#\(nop\) *([A-Z]+) (.*)/);
216+
return {
217+
key,
218+
...parseCreatedBy(value),
219+
};
191220
case 'size':
192-
return bytesToSize(value);
221+
return { key, value: bytesToSize(value) };
193222
case 'Entrypoint':
194223
case 'Cmd':
195-
return (value || []).join(' ');
224+
return { key, value: (value || []).join(' ') };
196225
case 'Labels':
197-
return Object.keys(value || {}).map(function (elt) {
198-
return value[elt] ? elt + '=' + value[elt] : '';
199-
});
226+
return {
227+
key,
228+
value: Object.keys(value || {}).map(function (elt) {
229+
return value[elt] ? elt + '=' + value[elt] : '';
230+
}),
231+
};
200232
case 'Volumes':
201233
case 'ExposedPorts':
202-
return Object.keys(value);
234+
return { key, value: Object.keys(value) };
203235
}
204-
return value || '';
236+
return { key, value: value || '' };
205237
};
206238
207239
const getConfig = function (blobs, { historyCustomLabels }) {

0 commit comments

Comments
 (0)