Skip to content

Commit e5c388c

Browse files
committed
refactor to simplify plugin and focus on xkcd
1 parent de107c8 commit e5c388c

19 files changed

Lines changed: 201 additions & 387 deletions

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
.gradle
21
/build

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
all: install
2+
3+
clean:
4+
rm -rf build
5+
6+
build:
7+
mkdir -p build/libs build/zip-content/xkcd-ui
8+
cp -r resources plugin.yaml build/zip-content/xkcd-ui
9+
cd build/zip-content; zip -r xkcd-ui.zip *
10+
mv build/zip-content/xkcd-ui.zip build/libs
11+

README.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
1-
# Hello World - UI plugin demo
1+
# XKCD - UI plugin demo
22

3-
This plugin includes some basic UI demostrations:
3+
This plugin uses javascript + a mocked ajax request to modify Jobs list page
44

5-
* Usage of i18n to get messages
6-
* Usage of javascript to modify Main Page
7-
* Usage of javascript + ajax request to modify Jobs list page
8-
* Usage of javascript + css to modify the execution page
9-
10-
### Hello World.
11-
12-
(Disabled by default. It can be enabled on `main.js` code)
13-
Display `Hello world` text from `messages.properties`, if the user change the language to Spanish on Rundeck, the message changes to `Hola Mundo`.
14-
15-
### XKCD random image.
16-
17-
(Enabled by default)
185
On the jobs page, it adds on top of the job list, a random image from a json source file.
196
To retrieve this image, the code uses a ajax call to a local file, this can be replaced with a call to a webservice on the same server as the rundeck instance.
207

21-
Since rundeck 3.0.12 you need to add this to `rundeck-config.properties`:
22-
`rundeck.security.httpHeaders.provider.csp.config.img-src=self https://imgs.xkcd.com`
23-
24-
### Panic mode
25-
26-
(Disabled by default. It can be enabled on `main.js` code)
27-
On the execution page, changes the header to red when a failed execution is open.
28-
29-
308

319
## Update the xkcd source
3210

3311
Edit `getSources.sh` Set TODAY to the latest xkcd comic of the day.
3412
Run:
3513
`./getSources.sh > xkcdsource.json`
14+
15+
## Build
16+
17+
Using make:
18+
```
19+
make clean build
20+
```
21+
22+
## Install
23+
24+
```
25+
cp build/libs/xkcd-ui.zip $RDECK_BASE/libext
26+
```
27+
28+
XKCD is A webcomic of romance, sarcasm, math, and language. By Randall Munroe, see more about xkcd here => https://xkcd.com
29+

build.gradle

Lines changed: 0 additions & 128 deletions
This file was deleted.

getSources.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
TODAY=2109
2+
TODAY=2165
33
START=$TODAY-365
44
echo "{ \"list\": ["
55

plugin.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: xkcd-ui
2+
rundeckPluginVersion: 2.0
3+
author: Rundeck Dev
4+
description: Describe your plugin here
5+
rundeckCompatibilityVersion: 3.x
6+
targetHostCompatibility: unix
7+
license: Apache 2.0
8+
tags:
9+
- script
10+
- UI
11+
date: 2019-06-14T20:45:04.155Z
12+
version: 1.0.0
13+
providers:
14+
- name: xkcd-ui
15+
service: UI
16+
plugin-type: ui
17+
title: XKCD UI
18+
description: Rundeck UI test
19+
ui:
20+
- pages: '*'
21+
scripts:
22+
- js/xkcd-init.js
23+
- js/main.js
24+
styles:
25+
- css/ui-example-styles.css
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
body {
2+
font-variant:small-caps;
3+
font-family:Lucida,Helvetica,sans-serif;
4+
font-weight:500;
5+
}
6+
/* line 1, paper/_typography.scss */
7+
h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6, p, .navbar, .brand, a, .td-name, td {
8+
font-variant:small-caps;
9+
font-family:Lucida,Helvetica,sans-serif;
10+
font-weight:500;
11+
text-decoration: none;
12+
}
13+
14+
.sidebar .logo a.home {
15+
font-family:Lucida,Helvetica,sans-serif;
16+
}
17+
18+
.mainbar {
19+
background-image: url('../icon.png');
20+
text-transform: uppercase;
21+
color: #ffffff;
22+
padding-left: 80px;
23+
24+
background-size: 80px;
25+
background-repeat: no-repeat;
26+
width: 100%;
27+
display: block;
28+
background-position-y: 10px;
29+
background-position-x: 20px;
30+
}

resources/icon.png

10.7 KB
Loading

resources/js/main.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
function initXKCD() {
3+
var project = rundeckPage.project();
4+
var path = rundeckPage.path();
5+
var para = document.createElement("div");
6+
7+
para.style.fontSize = "150%";
8+
para.style.textAlign = "center";
9+
para.style.marginBottom = "10px";
10+
11+
var xkcd = document.createElement("div");
12+
xkcd.id = "xkcdfield";
13+
para.appendChild(xkcd);
14+
15+
var x = jQuery(".main-panel .content").prepend(para);
16+
17+
if(rundeckPage.path() === "menu/jobs"){
18+
//on any project page
19+
jQuery.ajax({
20+
beforeSend: function(xhr){
21+
if (xhr.overrideMimeType)
22+
{
23+
xhr.overrideMimeType("application/json");
24+
}
25+
},
26+
dataType: 'json',
27+
url: url_path(rundeckPage.pluginBasei18nUrl('xkcd-ui'))+'/service/xkcdsource.json',
28+
success: function (data) {
29+
var imgCount = data.list.length;
30+
var n = Math.floor(Math.random() * imgCount);
31+
var image = data.list[n];
32+
if(image.img){
33+
jQuery("#xkcdfield").prepend(jQuery('<img>',{id:'xcdImg',src:image.img, title:image.alt}));
34+
}
35+
}
36+
});
37+
}
38+
};
39+
40+
function url_path(baseUrl) {
41+
if (baseUrl.indexOf('/') == 0) {
42+
return baseUrl;
43+
}
44+
if (baseUrl.toLowerCase().indexOf('http') == 0) {
45+
var len = baseUrl.indexOf('://');
46+
if (len > 0) {
47+
var absurl = baseUrl.substring(len + 3);
48+
if (absurl.indexOf('/') >= 0) {
49+
absurl = absurl.substring(absurl.indexOf('/'));
50+
return absurl;
51+
} else {
52+
return '';
53+
}
54+
}
55+
}
56+
}

resources/js/xkcd-init.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jQuery(document).on('load.rundeck.page', function () {
2+
initXKCD()
3+
});

0 commit comments

Comments
 (0)