Skip to content

Commit

Permalink
Add immediate IP-based logging in, add quinary class suggestion, polish
Browse files Browse the repository at this point in the history
  • Loading branch information
blokhin committed Nov 24, 2024
1 parent ce6db0a commit ce4b635
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 60 deletions.
17 changes: 3 additions & 14 deletions labs/pd3d/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#main{width:90%;margin:0 auto;}
#overlay{display:block;position:fixed;left:0;top:0;width:100%;height:100%;text-align:center;z-index:300;overflow:hidden;background:#fff;}
#notifybox{display:block;position:fixed;left:50%;top:7%;margin-left:-250px;width:500px;text-align:center;z-index:301;background:#eee;border-radius:10px;font-size:1.1em;line-height:2.15em;}
#cross{display:none;position:fixed;top:6px;right:6px;width:24px;height:24px;z-index:302;cursor:pointer;background:url(data:image/gif;base64,R0lGODlhEAAQAJEAAAAAAP///1VVVf///yH5BAEAAAMALAAAAAAQABAAAAIjnI+py6L+BDRy0gqxHVqvLjGcJ3Yl+IEhQpLX+m7wMYv2PRQAOw==) center center no-repeat;}

h1{text-align:center;font-weight:normal;font-size:4vmin;margin:2vmin auto;}
#tool{padding-top:25%;width:400px;margin:0 auto;}
Expand Down Expand Up @@ -49,9 +48,6 @@ <h1>Dynamically compile 3d phase diagrams</h1>
<div id="spinner"><div id="logo"></div></div>
<div id="notifybox"></div>

<!-- POSSIBILITY TO CLOSE FROM IFRAME -->
<div id="cross" title="Close" class="uielem"></div>

<script type="text/javascript">
"use strict";

Expand Down Expand Up @@ -93,9 +89,9 @@ <h1>Dynamically compile 3d phase diagrams</h1>
if (window.xhr.status == 200 || window.xhr.status == 400)
handle_resp(JSON.parse(window.xhr.responseText));
else if (window.xhr.status)
notify('Error: HTTP error ' + window.xhr.status + ' received during retrieving data from the server');
window.notify('Error: HTTP error ' + window.xhr.status + ' received during retrieving data from the server');
else
notify('Error: no response received');
window.notify('Error: no response received');
}
}
show_preloader();
Expand Down Expand Up @@ -162,17 +158,10 @@ <h1>Dynamically compile 3d phase diagrams</h1>
}

try {
window.mpds_embedded = !!(window.parent && window.parent.wmgui && window.parent.wmgui.view_mode == 2);
window.mpds_embedded = window.parent && window.parent.wmgui;
} catch (e){}

if (window.mpds_embedded){

document.getElementById('cross').style.display = 'block';

document.getElementById('cross').onclick = function(){
window.parent.close_vibox();
}

window.notify = function(msg){
document.getElementById('notifybox').innerHTML = msg;
document.getElementById('notifybox').style.display = 'block';
Expand Down
23 changes: 18 additions & 5 deletions src_js/main_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ function describe_perms(perms){

if (perms.api){
if (perms.api.root) out_api += '<li>complete access</li>';
else if (perms.api.disabled) out_api += '<li>disabled; please check on the other device</li>';
else if (perms.api.disabled) out_api += '<li>disabled &mdash; please check on the other device</li>';
else {
if (!$.isArray(perms.api)) perms.api = [perms.api];
$.each(perms.api, function(m, ruleset){
Expand Down Expand Up @@ -1301,8 +1301,19 @@ function init_user_login(){
if (locals.sid === wmgui.sid)
return;

if (locals.sid && locals.name && locals.acclogin){
user_login(locals.sid, locals.name, locals.acclogin, locals.admin, locals.oauths, locals.ipbased);
if (!locals.ipbased && locals.sid && locals.name && locals.acclogin){
user_login(locals.sid, locals.name, locals.acclogin, locals.admin, locals.oauths, false);

} else {
// attempt IP-based login
$.ajax({
type: 'POST',
url: wmgui.ip_endpoint,

}).done(function(data){
if (data.sid && data.name && data.acclogin)
user_login(data.sid, data.name, data.acclogin, data.admin, data.oauths, true);
});
}
}

Expand All @@ -1328,7 +1339,7 @@ function user_login(sid, name, acclogin, admin, oauths, ipbased){
ipbased: ipbased
})); // TODO? oauths: oauths

(admin && (wmgui.edition === 0 || wmgui.edition === 1 || wmgui.edition === 6)) ? $('li.admin').show() : $('li.admin').hide();
(admin && (wmgui.edition == 0 || wmgui.edition == 1)) ? $('li.admin').show() : $('li.admin').hide();

if (ipbased){
$('.only_regular').hide();
Expand Down Expand Up @@ -1405,7 +1416,9 @@ function force_relogin(show_msg){
function communicate_windows(runnable_name){
// NB the active window doesn't receive a storage event
window.localStorage.setItem(wmgui.store_comm_exec_key, runnable_name);
window.localStorage.removeItem(wmgui.store_comm_exec_key);
setTimeout(function(){
window.localStorage.removeItem(wmgui.store_comm_exec_key)
}, 0);
}

function reset_factor_form() {
Expand Down
29 changes: 7 additions & 22 deletions src_js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,29 +205,14 @@ function url__modal(arg){
if (wmgui.sid) return window.location.replace('#modal/menu');
//if (wmgui.sid) return window.location.replace('#start'); // for Matcloud

$.ajax({
type: 'POST',
url: wmgui.ip_endpoint,
// edition-based OAuth login (mpdsgui only)
if (wmgui.edition == 1){
return window.location.replace('oauth/asm.html');

}).done(function(data){

if (!data.sid || !data.name || !data.acclogin){

// edition-based OAuth login (mpdsgui only)
if (wmgui.edition == 1 || wmgui.edition == 6){
return window.location.replace('oauth/asm.html');
} /* else if (wmgui.edition == 11 || wmgui.edition == 16){
return window.location.replace('oauth/matcloud.html');
} */
return show_modal(arg);
}

user_login(data.sid, data.name, data.acclogin, data.admin, data.oauths, true);
$('#userbox').trigger('click');

}).fail(function(xhr, textStatus, errorThrown){
return show_modal(arg);
});
} /* else if (wmgui.edition == 16){
return window.location.replace('oauth/matcloud.html');
} */
show_modal(arg);

} else if (arg == "restore" || arg == "factor"){
if (wmgui.sid) return window.location.replace('#modal/menu');
Expand Down
1 change: 0 additions & 1 deletion src_js/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ satisfy_requirements();
register_events();

// use MPDS API, please

console.log("%cWeb-scraping or automated usage apart of the public MPDS API is in violation of our ToS (https://mpds.io/formal/terms) and results in banned account.", "color:red;font-size:16px;")
3 changes: 2 additions & 1 deletion src_js/third_party/optimade_mpds_nlp.js
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,9 @@ const OptimadeNLP = function () {
return [ 'elements', term.split('-').map((el) => capitalize(el)).join('-') ];
}

if (['element', 'elementary'].includes(term)) return ['classes', 'unary'];
if (['element', 'elementary', 'unitary'].includes(term)) return ['classes', 'unary'];
else if (
term === 'quintenary' ||
term === 'quinternary' ||
term === 'quinternaries' ||
term === 'quinaries' ||
Expand Down
24 changes: 10 additions & 14 deletions src_js/wmcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,17 @@ wmgui.get_random_term = function(sequence){
* Generate random sequences
*/

wmgui.get_realistic = function(facet, cur_arity){
wmgui.get_realistic = function(facet, cur_nlen){

var term;

if (facet == 'elements'){
var i = 0,
els = [],
prob_arity = [2, 3], // 4 is improbable
cur_arity = cur_arity || wmgui.get_random_term(prob_arity);
cur_nlen = cur_nlen || wmgui.get_random_term(prob_arity);

while (i < cur_arity){
while (i < cur_nlen){
var el;
if (i < 2)
el = wmgui.get_random_term(wmgui.probable_els);
Expand Down Expand Up @@ -314,7 +314,7 @@ wmgui.get_interpretation = function(search, facet_names, num_database){
if (!search) search = {};

var interpret_html = '',
cur_arity = false;
cur_nlen = 0;

$.each(search, function(k, val){
if (!facet_names[k] || !val) return true;
Expand All @@ -325,7 +325,7 @@ wmgui.get_interpretation = function(search, facet_names, num_database){

else if (k == 'elements'){
var els = val.split('-');
cur_arity = els.length; // els.length < 5
cur_nlen = els.length;
val = els.map(function(i){ return i.charAt(0).toUpperCase() + i.slice(1).toLowerCase() }).join(', ');

} else if (k == 'classes'){
Expand Down Expand Up @@ -383,23 +383,19 @@ wmgui.get_interpretation = function(search, facet_names, num_database){
return false;
}

if (cur_arity && (cur_arity - 1) > num)
if (cur_nlen - 1 > num)
return true;

if (num > 3)
return true;

else if (num == 5)
if ((cur_nlen < 4 && num > 3) || num > 4)
return false;

var addr;
if (window.location.hash.indexOf('inquiry') > -1){
if (window.location.hash.indexOf('classes=') > -1)
addr = window.location.hash.replace('classes=', 'classes=' + value + ',');
var addr = window.location.hash.replace('classes=', 'classes=' + value + ',');
else
addr = window.location.hash.replace('inquiry/', 'inquiry/classes=' + value + '&');
var addr = window.location.hash.replace('inquiry/', 'inquiry/classes=' + value + '&');

} else addr = window.location.hash + ' ' + value;
} else var addr = window.location.hash + ' ' + value;

arity_helper_html += '<li class="fct_classes" rel="' + addr + '" style="letter-spacing:0.5px;">Show only ' + value.substr(0, value.length - 1) + 'ies</li>';
});
Expand Down
4 changes: 2 additions & 2 deletions webassets/ermac.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ div.cross{float:right;width:16px;height:16px;font-size:10px;text-align:center;cu
div.cross:active{transform:translateY(1px);}
div.gear{float:right;margin:12px 2px 0 0;width:16px;height:16px;font-size:10px;text-align:center;cursor:pointer;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApQAAAKUBcMTeVQAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAHdSURBVDiNdZMxaBRREIa//7iNeGsKS5MIglaCKYSA4GGd61LsC+RsrAIWio2owUoIwRRK0MbuUhhxX7NWm0axMIVtLGwSEEJsDdweepeDsci7Ywmbrd4/M//M/8++J874nHPrwGMASetpmj6pqquPDq1W61wcx/cnJiY2t7a2/gA3RjkzmwVot9sXh8PhcqPR2Oh0Ov8AFKadB7aBO8C+mX2U9ACYDD26kt6a2RJwBdguimIhz/N+LUh8GMgAVyWtlMgAk2b2LJAB5uM4vgdQAxgMBu+AvQqLh8DvivhPSe/HDbIsO5LkSwUHkpre+xnv/bSkJnBQyn/y3hcASpLklaRZ4BYQB0vNNE13yiMXFxdvm9m3AAvgi6RdOefstGzv/UyFbJxzh8BUOVarqFMV+axcDXgBZEEWwJRzrlkxvQlcCrAHfDaz1+OOSZKsht8HJ0tcGu0h+P8AXAaQtJam6cpYknPuAvAduH5q8GGomToV3zs+Pp7LsuyoBmBmdyvIANMVZIBr9Xp9ebQDer1eh5OrDPBL0hrQLRG6wCqwH/BXSW/GDfI87xdFsSDpaRRFN4O/8j3Y8d4/j6JoDnhUFMW89/4vlF5jnud94OUIS9o1s/kAfwCEV7pR9vIf1VyoNh7B/AQAAAAASUVORK5CYII=) no-repeat;}

#notifybox{z-index:210;position:fixed;top:40px;right:20px;width:380px;background:#fc6;border-radius:5px;padding:20px;font-size:1.1em;line-height:1.5em;text-align:center;}
#notifybox{z-index:210;position:fixed;top:40px;right:6px;width:380px;background:#fc6;border-radius:5px;padding:20px;font-size:1.1em;line-height:1.5em;text-align:center;}
#notifybox > a{text-decoration:none;color:#3e3f95;border-bottom:1px solid #3e3f95;}

#ermac_logo{width:200px;height:200px;margin:0 auto;background:url(wm_logo_opt.png) center center no-repeat;background-size:75%;}
Expand Down Expand Up @@ -329,7 +329,7 @@ div.controlswitch > div.active, div.controlswitch > div:hover{background:#bfbfbf

/* USER ACCOUNT */

#userbox{position:fixed;top:0;right:0;height:34px;z-index:200;background:#fff;font-size:0.9em;color:#555;border-bottom-left-radius:4px;line-height:33px;padding:0 8px 0 3px;border-bottom:1px solid #888;border-left:1px solid #888;cursor:pointer;box-shadow:8px 8px 4px -3px rgba(0,0,0,0.4);overflow:hidden;}
#userbox{position:fixed;top:0;right:0;height:34px;z-index:200;background:#fff;font-size:0.9em;color:#555;border-bottom-left-radius:4px;line-height:33px;padding:0 8px 0 3px;border-bottom:1px solid #888;border-left:1px solid #888;cursor:pointer;box-shadow:8px 8px 4px -3px rgba(0,0,0,0.4);overflow:hidden;user-select:none;}
#userbox span{margin:0 3px;}
#userbox span.user_title{display:none;}
#userbox > div.logged_out{background:#fff;}
Expand Down
2 changes: 1 addition & 1 deletion webassets/pd_stub.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<body>

<div id="cross" title="Close"></div>
<div id="switcher" title="Switch between static and dynamic"></div>
<div id="switcher" title="Switch between static and dynamic view"></div>

<script type="text/javascript">
if (document.location.hash.length){
Expand Down

0 comments on commit ce4b635

Please sign in to comment.