Ero sivun ”Widget:Levätaulukko” versioiden välillä
Järvi-meriwikistä
Rivi 16: | Rivi 16: | ||
var vuosi = "<!--{$vuosi|default:1998|escape:'html'}-->"; | var vuosi = "<!--{$vuosi|default:1998|escape:'html'}-->"; | ||
var alue = "Merialue"; | var alue = "Merialue"; | ||
+ | var ely, meri; | ||
+ | |||
+ | if ( alue == 'Sisävedet' ) { | ||
+ | ely = 'ei'; | ||
+ | meri = 0; | ||
+ | } elseif ( alue == 'Merialue' ) { | ||
+ | ely = 'ei'; | ||
+ | meri = 1; | ||
+ | } else { | ||
+ | ely = alue.replace('ELY', 'elinkeino-, liikenne- ja ympäristökeskus'); | ||
+ | meri = 2; | ||
+ | } | ||
+ | |||
+ | var kunta = "<!--{$kunta|default:ei|escape:'html'}-->"; | ||
+ | |||
+ | var qtId = "<!--{$id|default:algalTable|escape:'html'}-->"; | ||
+ | |||
+ | var reqSuccess = false; | ||
+ | |||
+ | var meripaikkoja = false; | ||
+ | var numberOfRows = 0; | ||
+ | var maxRows = 0; | ||
+ | |||
+ | var exportCsv = ""; | ||
+ | var dataArr = new Array(); | ||
+ | |||
+ | var searchStr = "action=ask&query=[[Havainto::>0]]"; | ||
+ | searchStr += encodeURI("[[Tyyppi::Levätilanne]]"); | ||
+ | searchStr += encodeURI("[[Seuranta::Valtakunnallinen leväseuranta]]"); | ||
+ | searchStr += "[[Vuosi::" + vuosi + "]]"; | ||
+ | searchStr += "[[Viikko::>23]][[Viikko::<39]]"; | ||
+ | if (ely != "ei") { searchStr += "[[ELY-keskus::" + encodeURI(ely) + "]]"; } | ||
+ | if (kunta != "ei") { searchStr += "[[Kunta::" + encodeURI(kunta) + "]]"; } | ||
+ | if (meri == "0") { searchStr += encodeURI("[[Vesistö::Järvi||Joki]]"); } | ||
+ | else if (meri == "1") { searchStr += encodeURI("[[Vesistö::Meri]]"); } | ||
+ | |||
+ | searchStr += encodeURI("|?Havainto|?SiteID|?Vesistö|?Alue|?Järvi|?Vesistöalue|?Kunta|?Viikko|?Päivämäärä|?Levätilanne|sort=Päivämäärä|limit=10000"); | ||
+ | searchStr += '&format=json'; | ||
+ | console.log(searchStr); | ||
+ | jQuery.ajax({ | ||
+ | type: 'GET', | ||
+ | url: queryApi, | ||
+ | data: searchStr, | ||
+ | success: success, | ||
+ | dataType: 'jsonp' | ||
+ | }); | ||
+ | console.log(searchStr); | ||
+ | function progressIndicator(d) { | ||
+ | jQuery('#<!--{$id|default:JwAlgalTable|escape:'html'}-->_container').html('Ladataan tietoja (' + (maxRows-d) + '/' + maxRows + ')'); | ||
+ | } | ||
+ | |||
+ | function success(request) { | ||
+ | console.log(request); | ||
+ | reqSuccess = true; | ||
+ | |||
+ | if (request.query.results != undefined) { | ||
+ | |||
+ | var output = ""; | ||
+ | var lastSite = ""; | ||
+ | var lastWeek = 0; | ||
+ | output += '<div class="mw-content-ltr">' | ||
+ | output += '<table width="100%" class="tablesorter sortable jquery-tablesorter wikitable smwtable Xsmalltable2 tablecompact" id="<!--{$id|default:JwAlgalTable|escape:'html'}-->" >'; | ||
+ | output += '<thead><tr>'; | ||
+ | output += '<th class="headerSort " style="text-align: left;"></th>'; | ||
+ | output += '<th class="headerSort" style="text-align: left;">Vesistö</th>'; | ||
+ | output += '<th class="headerSort" style="text-align: left;">Nimi</th>'; | ||
+ | output += '<th class="headerSort" style="text-align: left;">Kunta</th>'; | ||
+ | output += '<th class="headerSort headerSortSmall" style="text-align: center;">23</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">24</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">25</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">26</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">27</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">28</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">29</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">30</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">31</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">32</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">33</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">34</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">35</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">36</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">37</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">38</th>'; | ||
+ | output += '<th class="headerSort headerSort-compact" style="text-align: center;">39</th>'; | ||
+ | output += '</tr></thead><tbody>'; | ||
+ | |||
+ | maxRows = request.query.results.length; | ||
+ | |||
+ | var siteIDs = new Object(); | ||
+ | |||
+ | for (var i in request.query.results) { | ||
+ | |||
+ | numberOfRows++; | ||
+ | progressIndicator(numberOfRows); | ||
+ | |||
+ | resultItem = request.query.results[i].printouts; | ||
+ | resultPage = resultItem.SiteID[0]; | ||
+ | |||
+ | siteIDs[resultPage] = resultPage; | ||
+ | |||
+ | if (dataArr[resultPage] == undefined) { | ||
+ | |||
+ | dataArr[resultPage] = new Object(); | ||
+ | dataArr[resultPage].url = "//www.jarviwiki.fi/wiki/index.php?curid=" + resultPage; | ||
+ | if (resultItem.Vesistö[0] == 'Meri') { | ||
+ | dataArr[resultPage].sea = true; | ||
+ | } else { | ||
+ | dataArr[resultPage].sea = false; | ||
+ | } | ||
+ | if (resultItem.Alue.length > 0) { | ||
+ | dataArr[resultPage].wBody = resultItem.Alue[0].fulltext; | ||
+ | dataArr[resultPage].wBodyUrl = resultItem.Alue[0].fullurl; | ||
+ | } else { | ||
+ | if (resultItem.Vesistö[0] == 'Järvi') { | ||
+ | dataArr[resultPage].wBody = resultItem.Järvi[0].fulltext; | ||
+ | dataArr[resultPage].wBodyUrl = resultItem.Järvi[0].fullurl; | ||
+ | } else { | ||
+ | dataArr[resultPage].wBody = resultItem.Vesistöalue[0].fulltext; | ||
+ | dataArr[resultPage].wBodyUrl = resultItem.Vesistöalue[0].fullurl; | ||
+ | } | ||
+ | } | ||
+ | dataArr[resultPage].mun = resultItem.Kunta[0].fulltext; | ||
+ | dataArr[resultPage].munUrl = resultItem.Kunta[0].fullurl; | ||
+ | dataArr[resultPage].weeks = new Array(); | ||
+ | } | ||
+ | |||
+ | resultWeek = resultItem.Viikko[0]; | ||
+ | |||
+ | dataArr[resultPage].weeks[resultWeek] = resultItem.Levätilanne[0]; | ||
+ | } | ||
+ | |||
+ | function doRows() { | ||
+ | |||
+ | for (var s in dataArr) { | ||
+ | |||
+ | site = dataArr[s]; | ||
+ | |||
+ | output += '<tr>'; | ||
+ | |||
+ | if (site.sea) { | ||
+ | meripaikkoja = true; | ||
+ | output += '<td data-sort-value="1" valign="middle" class="smwtype_qty">'; | ||
+ | output += '<a href="' + site.url + '" title="' + site.title + '">'; | ||
+ | output += '<img alt="Merialue" src="//www.jarviwiki.fi/w/images/a/ac/Pm_hp_asiantuntija_1_27x27.png" width="27" height="27" style="vertical-align: middle" />'; | ||
+ | output += '</a></td>'; | ||
+ | } else { | ||
+ | output += '<td data-sort-value="0" valign="middle" class="smwtype_qty">'; | ||
+ | output += '<a href="' + site.url + '" title="' + site.title + '">'; | ||
+ | output += '<img alt="Sisävesi" src="//www.jarviwiki.fi/w/images/f/f3/Pm_hp_asiantuntija_2_27x27.png" width="27" height="27" style="vertical-align: middle" />'; | ||
+ | output += '</a></td>'; | ||
+ | } | ||
+ | output += '<td class="smwtype_wpg"><a href="' + site.wBodyUrl + '">' + site.wBody + '</a></td>'; | ||
+ | nimi = site.title.substr(site.title.lastIndexOf('/')); | ||
+ | if (nimi.indexOf('(') != -1) { | ||
+ | nimi = nimi.substr(nimi.indexOf('(')); | ||
+ | nimi = nimi.substr(1); | ||
+ | nimi = nimi.substr(0, nimi.length-1); | ||
+ | } else { | ||
+ | nimi = ""; | ||
+ | } | ||
+ | output += '<td class="smwtype_wpg">' + nimi + '</td>'; | ||
+ | output += '<td class="smwtype_wpg"><a href="' + site.munUrl + '">' + site.mun + '</a></td>'; | ||
+ | |||
+ | for (x = 23; x < 40; x++) { | ||
+ | |||
+ | if (site.weeks[x] != undefined) { | ||
+ | resultAlgalVal = site.weeks[x]; | ||
+ | if (resultAlgalVal == 0) { | ||
+ | exportCsv += ";0"; | ||
+ | output += '<td data-sort-value="0" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:none">0</td>'; | ||
+ | } else if (resultAlgalVal == 1) { | ||
+ | exportCsv += ";1"; | ||
+ | output += '<td data-sort-value="1" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:#6a9d38">1</td>'; | ||
+ | } else if (resultAlgalVal == 2) { | ||
+ | exportCsv += ";2"; | ||
+ | output += '<td data-sort-value="2" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:#fd9f00">2</td>'; | ||
+ | } else { | ||
+ | exportCsv += ";3"; | ||
+ | output += '<td data-sort-value="3" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:#c80000">3</td>'; | ||
+ | } | ||
+ | } else { | ||
+ | output += '<td data-sort-value="-1" class="smwtype_qty" style="text-align: center; vertical-align: middle; background-color:none">-</td>'; | ||
+ | } | ||
+ | |||
+ | } | ||
+ | output += '</tr>'; | ||
+ | } | ||
+ | |||
+ | output += '</tbody><tfoot></tfoot></table></div>'; | ||
+ | if (meripaikkoja) { | ||
+ | //output += '<div style="border: 0; float: left; margin-left: 13px;"><p class="kuvateksti"><a href="/w/images/a/ac/Pm_hp_asiantuntija_1_27x27.png"><img alt="Merialue" src="/w/images/thumb/a/ac/Pm_hp_asiantuntija_1_27x27.png/21px-Pm_hp_asiantuntija_1_27x27.png" width="21" height="21" /></a> = Merialueen havaintopaikka</p></div>'; | ||
+ | } | ||
+ | //output += '<div style="border: 0; float: right;"><p class="kuvateksti"> 0 = Ei levää | 1 = Hieman levää | 2 = Runsaasti levää | 3 = Erittäin runsaasti levää | - = Ei havaintoa</p></div>'; | ||
+ | //output += '<div style="clear: both;"></div>'; | ||
+ | output += '</div>'; | ||
+ | |||
+ | jQuery("#<!--{$id|default:JwAlgalTable|escape:'html'}-->_container").html(output); | ||
+ | jQuery("#<!--{$id|default:JwAlgalTable|escape:'html'}-->").tablesorter(); | ||
+ | } | ||
+ | |||
+ | function gotSiteIDs(IDsReq) { | ||
+ | if (!!IDsReq.query.pages) { | ||
+ | for (var id in IDsReq.query.pages) { | ||
+ | if ( typeof IDsReq.query.pages[id].title === "undefined" ) { | ||
+ | dataArr[id].title = "-"; | ||
+ | } else { | ||
+ | dataArr[id].title = IDsReq.query.pages[id].title; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | IDblocks--; | ||
+ | if (IDblocks == 0) { | ||
+ | doRows(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | var siteIDsArr = new Array(); | ||
+ | for (var id in siteIDs) { | ||
+ | siteIDsArr.push(siteIDs[id]); | ||
+ | } | ||
+ | var IDblocks = 0; | ||
+ | |||
+ | if (siteIDsArr.length > 0) { | ||
+ | for (b=0; b < siteIDsArr.length; b+=50) { | ||
+ | IDblocks++; | ||
+ | searchSiteID = 'action=query&pageids=' + siteIDsArr.slice(b, b+50).join(encodeURI('|')) + '&format=json'; | ||
+ | jQuery.ajax({ | ||
+ | type: 'POST', | ||
+ | cache: false, | ||
+ | url: queryApi, | ||
+ | data: searchSiteID, | ||
+ | dataType: 'jsonp', | ||
+ | success: gotSiteIDs | ||
+ | }); | ||
+ | } | ||
+ | } else { | ||
+ | doRows(); | ||
+ | } | ||
+ | |||
+ | } else { | ||
+ | jQuery('#<!--{$id|default:JwAlgalTable|escape:'html'}-->').html('Hakuehtojen mukaisia tietoja ei löytynyt'); | ||
+ | } | ||
+ | //alert(exportCsv); | ||
+ | } | ||
+ | |||
+ | function lataaTiedot() { | ||
+ | var newWindow = window.open("","Lataa","width=300,height=300,scrollbars=1,resizable=1"); | ||
+ | |||
+ | newWindow.document.open(); | ||
+ | newWindow.document.write(exportCsv); | ||
+ | newWindow.document.close(); | ||
+ | |||
+ | //window.open('data:text/csv;charset=utf-8,' + escape(exportCsv)); | ||
+ | } | ||
+ | |||
+ | |||
} | } | ||
</script> | </script> | ||
</includeonly> | </includeonly> |