Skip to content

Commit 9108f63

Browse files
author
minjk-bl
committed
Add check version
1 parent 656feb2 commit 9108f63

File tree

9 files changed

+264
-26
lines changed

9 files changed

+264
-26
lines changed

css/component/infoModal.css

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#vp_infoModal {
2+
position: fixed;
3+
top: 0;
4+
left: 0;
5+
width: 100%;
6+
height: 100%;
7+
z-index: 400;
8+
background-color: rgba(0,0,0,.4);
9+
}
10+
.vp-infoModal-container {
11+
position: relative;
12+
left: 50%;
13+
top: 50%;
14+
transform:translate(-50%, -50%);
15+
width: 400px;
16+
height: 150px;
17+
padding: 2rem;
18+
background-color: white;
19+
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
20+
font-family: AppleSDGothicNeo;
21+
}
22+
.vp-infoModal-inner {
23+
width: 100%;
24+
height: 100%;
25+
border-radius: 30px;
26+
}
27+
.vp-infoModal-input-button:hover {
28+
cursor: pointer;
29+
transition: 0.7s;
30+
outline: 0;
31+
}
32+
.vp-infoModal-icon {
33+
font-size: 26px;
34+
color: var(--font-primary);
35+
}
36+
.vp-infoModal-titleStr {
37+
color: var(--font-primary);
38+
font-size: 13px;
39+
font-weight: 700;
40+
}
41+
.vp-infoModal-style-flex-column-evenly {
42+
display: flex;
43+
flex-direction: column;
44+
justify-content: space-evenly;
45+
}
46+
.vp-infoModal-style-flex-row-center {
47+
display: flex;
48+
flex-direction: row;
49+
justify-content: center;
50+
}
51+
.vp-infoModal-style-text-center {
52+
text-align: center;
53+
}

css/component/modal.css

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
padding: 2rem;
1919
background-color: white;
2020
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
21+
font-family: AppleSDGothicNeo;
2122
}
2223
#vp_multiButtonModal .vp-multi-button-modal-message {
2324
display: flex;
@@ -40,26 +41,6 @@
4041
align-items: center;
4142
height: 80%;
4243
}
43-
#vp_multiButtonModal .vp-modal-button {
44-
min-width: 100px;
45-
height: 30px;
46-
font-family: AppleSDGothicNeo;
47-
font-style: normal;
48-
font-weight: normal;
49-
font-size: 14px;
50-
line-height: 21px;
51-
text-align: center;
52-
color: var(--font-primary);
53-
background: #F5F5F5;
54-
border: 0.25px solid #C4C4C4;
55-
box-sizing: border-box;
56-
border-radius: 2px;
57-
}
58-
#vp_multiButtonModal .vp-modal-button:nth(2) {
59-
background-color: var(--font-hightlight);
60-
color: white;
61-
margin-right: 10px;
62-
}
6344
#vp_multiButtonModal .vp-multi-button-modal-buttons {
6445
display: flex;
6546
align-items: center;

html/component/infoModal.html

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!--
2+
Project Name : Visual Python
3+
Description : GUI-based Python code generator
4+
File Name : infoModal.html
5+
Author : Black Logic
6+
Note : Info modal
7+
License : GNU GPLv3 with Visual Python special exception
8+
Date : 2021. 12. 15
9+
Change Date :
10+
-->
11+
<!-- use body tag to strip comments out on requirejs/text plugin -->
12+
<body>
13+
<div id="vp_infoModal">
14+
<div class="vp-infoModal-container" >
15+
<div class="vp-infoModal-inner
16+
vp-infoModal-style-flex-column-evenly">
17+
18+
<div class="vp-infoModal-style-flex-row-center">
19+
<i class="fa fa-info-circle
20+
vp-infoModal-icon" aria-hidden="true">
21+
</i>
22+
</div>
23+
24+
<div class="vp-infoModal-titleStr
25+
vp-infoModal-style-text-center
26+
vp-infoModal-style-font-weight-700">
27+
28+
</div>
29+
<div class="vp-infoModal-style-flex-row-center">
30+
<input class="vp-infoModal-yes vp-button" type="submit" value="OK" />
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
</body>

html/menuFrame.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<li id="vp_restart" data-menu="restart">
2323
Restart visualpython
2424
</li>
25+
<li id="vp_checkVersion" data-menu="check-version">
26+
Check version
27+
</li>
2528
<hr class="vp-extra-menu-line"/>
2629
<li id="vp_extraMenuAbout" data-menu="about">
2730
About Visual Python

js/com/com_Config.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,47 @@ define(['./com_Const'], function(com_Const) {
314314
Jupyter.notebook.metadata[configKey] = {};
315315
}
316316

317+
/**
318+
* Check vp pypi package version (Promise)
319+
* usage:
320+
* vpConfig.getPackageVersion('visualpython').then(function(version) {
321+
* // do something after loading version
322+
* ...
323+
* }).catch(function(err) {
324+
* // error handling
325+
* ...
326+
* })
327+
*/
328+
getPackageVersion(packName='visualpython') {
329+
let url = `https://pypi.org/pypi/${packName}/json`;
330+
// using the Fetch API
331+
return new Promise(function(resolve, reject) {
332+
try {
333+
fetch(url).then(function (response) {
334+
if (response.ok) {
335+
return response.json();
336+
} else {
337+
throw new Error('Error', response);
338+
}
339+
}).then(function (data) {
340+
resolve(data.info.version);
341+
}).catch(function(err) {
342+
let errMsg = err.message;
343+
if (errMsg.includes('Failed to fetch')) {
344+
errMsg = 'Network connection error';
345+
}
346+
reject(errMsg);
347+
});
348+
} catch (err) {
349+
reject(err);
350+
}
351+
});
352+
}
353+
354+
getVpInstalledVersion() {
355+
return Config.version;
356+
}
357+
317358
}
318359

319360
//========================================================================
@@ -325,6 +366,11 @@ define(['./com_Const'], function(com_Const) {
325366
// Config.serverMode = _MODE_TYPE.DEVELOP;
326367
Config.serverMode = _MODE_TYPE.RELEASE;
327368

369+
/**
370+
* Version
371+
*/
372+
Config.version = "2.0.1";
373+
328374
/**
329375
* Type of mode
330376
*/

js/com/com_util.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ define([
146146
}
147147
}
148148

149+
/**
150+
* Modal
151+
* @param {Object} config { title, message, buttons(list), final(function), defaultIdx(int) }
152+
*/
153+
var renderModal = function(config={title:'', message:'', buttons:['Ok']}) {
154+
require(['vp_base/js/com/component/Modal'], function(Modal) {
155+
let modal = new Modal(config);
156+
modal.open();
157+
});
158+
}
159+
160+
/**
161+
* InfoModal
162+
* @param {string} titleStr
163+
*/
164+
var renderInfoModal = function(titleStr) {
165+
require(['vp_base/js/com/component/InfoModal'], function(InfoModal) {
166+
new InfoModal(titleStr);
167+
});
168+
}
169+
149170
/**
150171
* AlertModal
151172
* @param {string} titleStr
@@ -219,6 +240,8 @@ define([
219240
convertToStr: convertToStr,
220241

221242
removeHeadScript: removeHeadScript,
243+
renderModal: renderModal,
244+
renderInfoModal: renderInfoModal,
222245
renderAlertModal: renderAlertModal,
223246
renderSuccessMessage: renderSuccessMessage,
224247

js/com/component/InfoModal.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Project Name : Visual Python
3+
* Description : GUI-based Python code generator
4+
* File Name : InfoModal.js
5+
* Author : Black Logic
6+
* Note : InfoModal
7+
* License : GNU GPLv3 with Visual Python special exception
8+
* Date : 2021. 11. 18
9+
* Change Date :
10+
*/
11+
12+
//============================================================================
13+
// [CLASS] InfoModal
14+
//============================================================================
15+
define([
16+
'text!vp_base/html/component/infoModal.html!strip',
17+
'css!vp_base/css/component/infoModal.css',
18+
'vp_base/js/com/component/Component'
19+
], function(msgHtml, msgCss, Component) {
20+
21+
/**
22+
* InfoModal
23+
*/
24+
class InfoModal extends Component {
25+
constructor(title) {
26+
super($('body'), { title: title });
27+
}
28+
29+
_bindEvent() {
30+
let that = this;
31+
// click ok button
32+
$(this.wrapSelector('.vp-infoModal-yes')).click( function() {
33+
that.remove();
34+
});
35+
}
36+
37+
template() {
38+
return msgHtml;
39+
}
40+
41+
render() {
42+
super.render();
43+
44+
// set title
45+
$(this.wrapSelector('.vp-infoModal-titleStr')).text(this.state.title);
46+
}
47+
48+
remove() {
49+
$(this.wrapSelector()).remove();
50+
}
51+
52+
}
53+
54+
return InfoModal;
55+
});

js/com/component/Modal.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ define([
2929
* - title : string / modal title
3030
* - message : string / modal message
3131
* - buttons : list / at least 1 button needed
32-
* - defaultButtonIdx : int
32+
* [optional]
33+
* - defaultButtonIdx : int (default: 1)
3334
* - finish : callback function when modal button clicked (result:button idx 0~n)
35+
* - buttonClass : list / same length as buttons, define classes for buttons
3436
*/
3537
constructor(state) {
3638
super($('body'), state);
@@ -42,7 +44,10 @@ define([
4244
message: '',
4345
buttons: [],
4446
defaultButtonIdx: 1,
45-
finish: null,
47+
finish: function(modalIdx) {
48+
/* Implementation needed */
49+
},
50+
buttonClass: [],
4651
...this.state
4752
}
4853
/** Write codes executed before rendering */
@@ -72,7 +77,7 @@ define([
7277

7378
template() {
7479
/** Implement generating template */
75-
let { title, message, buttons, defaultButtonIdx } = this.state;
80+
let { title, message, buttons, defaultButtonIdx, buttonClass } = this.state;
7681
var sbTagString = new com_String();
7782
sbTagString.appendLine("<div id='vp_multiButtonModal'>");
7883
sbTagString.appendLine("<div class='vp-multi-button-modal-box'>");
@@ -85,8 +90,9 @@ define([
8590
sbTagString.appendLine("<div class='vp-multi-button-modal-buttons'>");
8691

8792
buttons && buttons.forEach((btn, idx) => {
88-
sbTagString.appendFormatLine("<input class='vp-modal-button {0}' data-idx={1} type='button' value='{2}' />",
93+
sbTagString.appendFormatLine("<input class='vp-button vp-modal-button {0} {1}' data-idx={2} type='button' value='{3}' />",
8994
defaultButtonIdx == idx? 'vp-modal-selected-button' : '',
95+
buttonClass[idx],
9096
idx,
9197
btn);
9298
});

js/menu/MenuFrame.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ define([
1717
'css!../../css/menuFrame.css',
1818

1919
'../com/com_Config',
20-
'../com/com_Const',
20+
'../com/com_util',
21+
'../com/com_interface',
2122
'../com/component/Component',
2223
'../com/component/SuggestInput',
2324

@@ -26,7 +27,7 @@ define([
2627
'./MenuGroup',
2728
'./MenuItem',
2829
'./TaskBar'
29-
], function(menuFrameHtml, menuFrameCss, com_Config, com_Const, Component, SuggestInput,
30+
], function(menuFrameHtml, menuFrameCss, com_Config, com_util, com_interface, Component, SuggestInput,
3031
librariesJson,
3132
MenuGroup, MenuItem, TaskBar) {
3233
'use strict';
@@ -85,6 +86,41 @@ define([
8586
$(this.wrapSelector('#vp_headerExtraMenu li')).on('click', function() {
8687
let menu = $(this).data('menu');
8788
switch(menu) {
89+
case 'check-version':
90+
// check vp version
91+
let nowVersion = vpConfig.getVpInstalledVersion();
92+
vpConfig.getPackageVersion().then(function(latestVersion) {
93+
if (nowVersion === latestVersion) {
94+
// if it's already up to date
95+
let msg = com_util.formatString('Visualpython is up to date. ({0})', latestVersion);
96+
com_util.renderInfoModal(msg);
97+
} else {
98+
let msg = com_util.formatString('Visualpython updates are available.\n(Latest version: {0})', latestVersion);
99+
com_util.renderModal({
100+
title: 'Check version',
101+
message: msg,
102+
buttons: ['Cancel', 'Update'],
103+
defaultButtonIdx: 0,
104+
buttonClass: ['cancel', 'activated'],
105+
finish: function(clickedBtnIdx) {
106+
switch (clickedBtnIdx) {
107+
case 0:
108+
// cancel
109+
break;
110+
case 1:
111+
// update
112+
com_interface.insertCell('code', '!pip install visualpython --upgrade');
113+
com_interface.insertCell('code', '!visualpy install');
114+
// TODO: refresh browser, after executed
115+
break;
116+
}
117+
}
118+
})
119+
}
120+
}).catch(function(err) {
121+
com_util.renderAlertModal(err);
122+
})
123+
break;
88124
case 'restart':
89125
// restart vp
90126
vpConfig.readKernelFunction();

0 commit comments

Comments
 (0)