fix: [Flask] remove hardcoded url

This commit is contained in:
Terrtia 2018-09-25 14:37:14 +02:00
parent b575efcc46
commit b3923428e5
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
10 changed files with 136 additions and 70 deletions

View file

@ -24,8 +24,7 @@
window.glob_tabvar = []; // Avoid undefined window.glob_tabvar = []; // Avoid undefined
window.threshold_stucked_module = {{ threshold_stucked_module }} window.threshold_stucked_module = {{ threshold_stucked_module }}
function update_values() { function update_values() {
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }}; $.getJSON("{{ url_for('dashboard.stuff') }}",
$.getJSON($SCRIPT_ROOT+"/_stuff",
function(data) { function(data) {
window.glob_tabvar = data; window.glob_tabvar = data;
}); });
@ -189,14 +188,16 @@
</div> </div>
<script> var url_showSavedPath = "{{ url_for('showsavedpastes.showsavedpaste') }}"; </script> <script> var url_showSavedPath = "{{ url_for('showsavedpastes.showsavedpaste') }}"; </script>
<script type="text/javascript" src="{{ url_for('static', filename='js/indexjavascript.js')}}"></script> <script type="text/javascript" src="{{ url_for('static', filename='js/indexjavascript.js')}}"
data-urlstuff="{{ url_for('dashboard.stuff') }}" data-urllog="{{ url_for('dashboard.logs') }}">
</script>
<script> <script>
activePage = "page-index"; activePage = "page-index";
$("#"+activePage).addClass("active"); $("#"+activePage).addClass("active");
var tableBody = document.getElementById('tab_body') var tableBody = document.getElementById('tab_body')
$.getJSON('/_get_last_logs_json', function(data) { $.getJSON("{{ url_for('dashboard.get_last_logs_json') }}", function(data) {
data.forEach(function (d) { data.forEach(function (d) {
var tr = document.createElement('TR') var tr = document.createElement('TR')
var time = document.createElement('TD') var time = document.createElement('TD')

View file

@ -127,7 +127,9 @@
$("#"+activePage).addClass("active"); $("#"+activePage).addClass("active");
}); });
</script> </script>
<script src="{{ url_for('static', filename='js/sentiment_plot.js') }}"></script> <script src="{{ url_for('static', filename='js/sentiment_plot.js') }}"
data-url_sentiment_analysis="{{ url_for('sentiments.sentiment_analysis_plot_tool_getdata') }}">
</script>
</body> </body>
</html> </html>

View file

@ -230,7 +230,9 @@
<!-- import graph function --> <!-- import graph function -->
<script src="{{ url_for('static', filename='js/sentiment_trending.js') }}"></script> <script src="{{ url_for('static', filename='js/sentiment_trending.js') }}"
data-url_sentiment_analysis_getplotdata="{{ url_for('sentiments.sentiment_analysis_getplotdata') }}">
</script>
<script> <script>
$("#LoadAll").hide(); $("#LoadAll").hide();

View file

@ -55,10 +55,11 @@
<script> <script>
var chart_1_num_day = 5; var chart_1_num_day = 5;
var chart_2_num_day = 15; var chart_2_num_day = 15;
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
</script> </script>
<script type="text/javascript" src="{{ url_for('static', filename='js/trendingchart.js')}}"></script> <script type="text/javascript" src="{{ url_for('static', filename='js/trendingchart.js')}}"
data-url_progressionCharts="{{ url_for('trendings.progressionCharts') }}">
</script>
<div class="tab-content"> <div class="tab-content">
<div class="col-lg-12 tab-pane fade in active" id="tld-tab" > <div class="col-lg-12 tab-pane fade in active" id="tld-tab" >

View file

@ -34,10 +34,12 @@
<script> <script>
var chart_1_num_day = 5; var chart_1_num_day = 5;
var chart_2_num_day = 15; var chart_2_num_day = 15;
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
</script> </script>
<script src="{{ url_for('static', filename='js/moduleTrending.js') }}"></script> <script src="{{ url_for('static', filename='js/moduleTrending.js') }}"
data-url_providersChart="{{ url_for('trendingmodules.providersChart') }}"
data-url_moduleCharts="{{ url_for('trendingmodules.modulesCharts') }}">
</script>
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
activePage = "page-modulestats" activePage = "page-modulestats"

View file

@ -3,6 +3,19 @@ var data_for_processed_paste = {};
var list_feeder = []; var list_feeder = [];
window.paste_num_tabvar_all = {}; window.paste_num_tabvar_all = {};
function getSyncScriptParams() {
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript;
return {
urlstuff : scriptName.getAttribute('data-urlstuff'),
urllog : scriptName.getAttribute('data-urllog')
};
}
var urlstuff = getSyncScriptParams().urlstuff;
var urllog = getSyncScriptParams().urllog;
//If we do not received info from mixer, set pastes_num to 0 //If we do not received info from mixer, set pastes_num to 0
function checkIfReceivedData(){ function checkIfReceivedData(){
for (i in list_feeder) { for (i in list_feeder) {
@ -27,8 +40,7 @@ function initfunc( csvay, scroot) {
}; };
function update_values() { function update_values() {
$SCRIPT_ROOT = window.scroot ; $.getJSON(urlstuff,
$.getJSON($SCRIPT_ROOT+"/_stuff",
function(data) { function(data) {
window.glob_tabvar = data; window.glob_tabvar = data;
}); });
@ -122,7 +134,7 @@ function initfunc( csvay, scroot) {
window.scroot = scroot; window.scroot = scroot;
}; };
var source = new EventSource('/_logs'); var source = new EventSource(urllog);
source.onmessage = function(event) { source.onmessage = function(event) {
var feed = jQuery.parseJSON( event.data ); var feed = jQuery.parseJSON( event.data );

View file

@ -5,6 +5,18 @@
* *
*/ */
function getSyncScriptParams() {
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript;
return {
url_providersChart : scriptName.getAttribute('data-url_providersChart'),
url_moduleCharts : scriptName.getAttribute('data-url_moduleCharts'),
};
}
var url_providersChart = getSyncScriptParams().url_providersChart;
var url_moduleCharts = getSyncScriptParams().url_moduleCharts;
/* VARIABLES */ /* VARIABLES */
var pie_threshold = 0.05 var pie_threshold = 0.05
@ -48,11 +60,12 @@ function plot_top_graph(module_name, init){
/**** Pie Chart ****/ /**** Pie Chart ****/
// moduleCharts is used the decide the url to request data // moduleCharts is used the decide the url to request data
var moduleCharts = "size" == module_name ? "providersChart" : ("num" == module_name ? "providersChart" : "moduleCharts"); var moduleCharts = "size" == module_name ? url_providersChart : ("num" == module_name ? url_providersChart : url_moduleCharts);
console.log(moduleCharts)
var tot_sum = 0; // used to detect elements placed in 'Other' pie's part var tot_sum = 0; // used to detect elements placed in 'Other' pie's part
var data_other = []; // used to detect elements placed in 'Other' pie's part var data_other = []; // used to detect elements placed in 'Other' pie's part
var createPie = $.getJSON($SCRIPT_ROOT+"/_"+moduleCharts+"?moduleName="+module_name+"&num_day="+chart_1_num_day, var createPie = $.getJSON(moduleCharts+"?moduleName="+module_name+"&num_day="+chart_1_num_day,
function(data) { function(data) {
var temp_data_pie = []; var temp_data_pie = [];
for(i=0; i<data.length; i++){ for(i=0; i<data.length; i++){
@ -137,7 +150,7 @@ function plot_top_graph(module_name, init){
for(i=0; i<data_other.length; i++){ // Get data for elements summed up in the part 'Other' for(i=0; i<data_other.length; i++){ // Get data for elements summed up in the part 'Other'
involved_item = data_other[i]; involved_item = data_other[i];
var request = $.getJSON($SCRIPT_ROOT+"/_"+chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day, var request = $.getJSON(chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day,
function(data) { function(data) {
temp_data_bar = [] temp_data_bar = []
for(i=1; i<data.length; i++){ for(i=1; i<data.length; i++){
@ -186,7 +199,7 @@ function plot_top_graph(module_name, init){
/* rememeber the data for the two provider graph */ /* rememeber the data for the two provider graph */
if (chartUrl == "providersChart"){ if (chartUrl == url_providersChart){
if (plot_data_old.length>1){ // avoid adding plot_data for previous clicked pie part if (plot_data_old.length>1){ // avoid adding plot_data for previous clicked pie part
plot_data_old = []; plot_data_old = [];
plot_old = []; plot_old = [];
@ -207,7 +220,7 @@ function plot_top_graph(module_name, init){
} else { // Normal pie's part clicked } else { // Normal pie's part clicked
$.getJSON($SCRIPT_ROOT+"/_"+chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day, $.getJSON(chartUrl+"?keywordName="+involved_item+"&moduleName="+module_name+"&bar=true"+"&days="+num_day,
function(data) { function(data) {
var temp_data_bar = [] var temp_data_bar = []
for(i=1; i<data.length; i++){ for(i=1; i<data.length; i++){

View file

@ -2,9 +2,19 @@ var li_text = "<li><div class='checkbox'></div><label class='provider'><input va
var li_text_mid = "' type='checkbox'></input> " var li_text_mid = "' type='checkbox'></input> "
var li_text_end = "</label></li>" var li_text_end = "</label></li>"
function getSyncScriptParams() {
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript;
return {
url_sentiment_analysis : scriptName.getAttribute('data-url_sentiment_analysis'),
};
}
var url_sentiment_analysis = getSyncScriptParams().url_sentiment_analysis;
/* Get Providers List and display them by row */ /* Get Providers List and display them by row */
$.getJSON('/sentiment_analysis_plot_tool_getdata/?getProviders=True', function(data){ $.getJSON(url_sentiment_analysis + '?getProviders=True', function(data){
for(i=0; i<data.length; i++){ for(i=0; i<data.length; i++){
var providerList = i%2 == 0 ? '#providerList1' : '#providerList2'; var providerList = i%2 == 0 ? '#providerList1' : '#providerList2';
$(providerList).append(li_text + data[i] + li_text_mid + data[i] + li_text_end); $(providerList).append(li_text + data[i] + li_text_mid + data[i] + li_text_end);
@ -64,7 +74,7 @@ function plotData(){
// retreive the data from the server // retreive the data from the server
$.getJSON('/sentiment_analysis_plot_tool_getdata/?getProviders=False&query='+query+'&Qdate='+Qdate, function(data){ $.getJSON(url_sentiment_analysis + '?getProviders=False&query='+query+'&Qdate='+Qdate, function(data){
var to_plot = []; var to_plot = [];
for (provider in data){ for (provider in data){
var nltk_data = Object.keys(data[provider]).map(function (key) { return data[provider][key]; }); var nltk_data = Object.keys(data[provider]).map(function (key) { return data[provider][key]; });

View file

@ -1,5 +1,17 @@
/* Functions and config */ /* Functions and config */
function getSyncScriptParams() {
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript;
return {
url_sentiment_analysis_getplotdata : scriptName.getAttribute('data-url_sentiment_analysis_getplotdata'),
};
}
var url_sentiment_analysis_getplotdata = getSyncScriptParams().url_sentiment_analysis_getplotdata;
function add_new_graph_today(id) { function add_new_graph_today(id) {
return "<div id=\"panel-today\" class=\"panel panel-default pannelToday"+id+"\">" + return "<div id=\"panel-today\" class=\"panel panel-default pannelToday"+id+"\">" +
"<div class=\"panel-heading\">" + "<div class=\"panel-heading\">" +
@ -100,7 +112,7 @@ var totNumGraph = 0;
// When everything is terminated, plot the widgets (Gauge, canvasJS, table) // When everything is terminated, plot the widgets (Gauge, canvasJS, table)
// input: all - set to 'True' if you take all providers // input: all - set to 'True' if you take all providers
function draw_page(all) { function draw_page(all) {
$.getJSON("/sentiment_analysis_getplotdata/?getProviders=True&all="+all, $.getJSON(url_sentiment_analysis_getplotdata + "?getProviders=True&all="+all,
function(data) { function(data) {
var promises = []; var promises = [];
@ -137,7 +149,7 @@ function draw_page(all) {
// input - provider: The povider name to be plotted // input - provider: The povider name to be plotted
// input - graphNum: The number of the graph (Use to plot on correct div) // input - graphNum: The number of the graph (Use to plot on correct div)
function query_and_plot(provider, graphNum) { function query_and_plot(provider, graphNum) {
var query_plot = $.getJSON("/sentiment_analysis_getplotdata/?provider="+provider, var query_plot = $.getJSON(url_sentiment_analysis_getplotdata + "?provider="+provider,
function(data) { function(data) {
var plot_data = []; var plot_data = [];
var array_provider = Object.keys(data); var array_provider = Object.keys(data);

View file

@ -6,6 +6,17 @@
* *
*/ */
function getSyncScriptParams() {
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript;
return {
url_progressionCharts : scriptName.getAttribute('data-url_progressionCharts'),
};
}
var url_progressionCharts = getSyncScriptParams().url_progressionCharts;
function plot_top_graph(trendingName, init){ function plot_top_graph(trendingName, init){
/**** Flot Pie Chart ****/ /**** Flot Pie Chart ****/
var tot_sum = 0; // used to detect elements placed in 'Other' pie's part var tot_sum = 0; // used to detect elements placed in 'Other' pie's part
@ -44,7 +55,7 @@ function plot_top_graph(trendingName, init){
// Graph1 // Graph1
$.getJSON($SCRIPT_ROOT+"/_progressionCharts?trendingName="+trendingName+"&num_day="+chart_1_num_day, $.getJSON(url_progressionCharts+"?trendingName="+trendingName+"&num_day="+chart_1_num_day,
function(data) { function(data) {
temp_data_pie = []; temp_data_pie = [];
for(i=0; i<data.length; i++){ for(i=0; i<data.length; i++){
@ -100,7 +111,7 @@ function plot_top_graph(trendingName, init){
for(i=0; i<data_other.length; i++){ // Get data for elements summed up in the part 'Other' for(i=0; i<data_other.length; i++){ // Get data for elements summed up in the part 'Other'
involved_item = data_other[i]; involved_item = data_other[i];
var request = $.getJSON($SCRIPT_ROOT+"/_progressionCharts?attributeName="+involved_item+"&bar=true"+"&days="+num_day, var request = $.getJSON(url_progressionCharts+"?attributeName="+involved_item+"&bar=true"+"&days="+num_day,
function(data) { function(data) {
temp_data_bar = [] temp_data_bar = []
for(i=1; i<data.length; i++){ for(i=1; i<data.length; i++){
@ -153,7 +164,7 @@ function plot_top_graph(trendingName, init){
} else { } else {
$.getJSON($SCRIPT_ROOT+"/_progressionCharts?attributeName="+involved_item+"&bar=true"+"&days="+num_day, $.getJSON(url_progressionCharts+"?attributeName="+involved_item+"&bar=true"+"&days="+num_day,
function(data) { function(data) {
var temp_data_bar = [] var temp_data_bar = []
for(i=1; i<data.length; i++){ for(i=1; i<data.length; i++){