Bugzilla – Attachment 60742 Details for
Bug 18066
Hea - Version 2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18066: Hea V2
Bug-18066-Hea-V2.patch (text/plain), 30.14 KB, created by
Chris Cormack
on 2017-02-28 21:06:25 UTC
(
hide
)
Description:
Bug 18066: Hea V2
Filename:
MIME Type:
Creator:
Chris Cormack
Created:
2017-02-28 21:06:25 UTC
Size:
30.14 KB
patch
obsolete
>From a24d9d8dad6ffdb897f642bc49b756b378097d67 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 2 Feb 2017 16:53:58 +0100 >Subject: [PATCH] Bug 18066: Hea V2 >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch is the Koha part of the Hea v2 project. >You can find the (testing) code for the server at > hea-ws - https://github.com/joubu/hea-ws/commits/v2 > hea-app - https://github.com/joubu/hea-app/commits/v2 >They contain the different pull requests made over the last 6 months. > >More information on Hea at https://wiki.koha-community.org/wiki/KohaUsageStat_RFC >The goal of this commit message is to provide an overview of what could >be a new version of Hea. > >Prior to these changes, the Hea database was filled with 1 line per Koha >installation. System preferences were filled by the libraries and a >cronjob (share_usage_with_koha_community.pl) collected these values to send >them to a webservice (hea-ws/upload.pl). > >With the need to collect more data we would want to collect data at the library >level (branch) and not at the installation level. >For instance the geolocation, the url or the country can be different from one >library to another, even if managed from the same Koha installation. >The Hea DB has been upgraded to reflect that change (see hea-app/sql/schema.sql). > >The hidden goal of this patch is to make Hea sexier and explain >better to libraries how it can be useful to share their information >with the Koha community. I guess the main problem is the lack of >communication and explanations about what we are doing we these data. >To fill this gap I'd like to (TODO) > 1. Communicate on the ML about this new version of Hea (once it got >pushed and backported) > 2. Link the Privacy_Policy.md from the Hea interface > 3. Get help from a native English speaker to add >popup/help/info/whatever on "Home ⺠Administration ⺠Usage statistics", >to clearly explain what happens (and what will not happen!) when an option or >another is set. > >You can find screenshot of this whole enhancement on bug 18066, comment 2. > >What this patch does: >- Create a new branches.geolocation DB field >- Add 3 new sysprefs: > * UsageStatsGeolocation > * UsageStatsLibrariesInfo > * UsageStatsPublicID >- Integrate the Leaflet JS library to get a fancy map to pick >geolocations > >How does it works: >On the new administration page where statistics to share are configured, >there are several new things. It is now possible to share information either >per Koha installation or libraries. If UsageStatsLibrariesInfo is set, >the info at library level (url, name, country, geolocation) will be >sent to the Hea webservice. If it is not set, you can decide to fill >UsageStatsLibraryUrl, UsageStatsLibraryName, UsageStatsCountry, >UsageStatsGeolocation to share these information. Note that even if the >data are retrieved at installation level, it's better to fill the prefs >as well: On the Hea website the different libraries defined for a given >Koha installation could be displayed on the same page. >This page is a public page which will be attributed to every >installation (with the pref UsageStatsPublicID). On this page all the >info available publicly will be displayed. > >TODO later: >- Add a button on the administration page to delete the info shared >publicly. It will be easy to show that the info are no longer displayed >on the public page. >- Add an icon per Koha installation to get a better "public page" >- Any suggestions? > >Test plan: >We will need to test hea-ws, hea-app and the Koha-side code to test the >whole enhancement. >1/ To start, clone the hea-ws and hea-app project and checkout the >'master' branch (*not* 'v2') >2/ Create the hea database and user > CREATE DATABASE hea > CREATE USER 'hea'@'localhost' IDENTIFIED BY 'hea'; > GRANT ALL PRIVILEGES ON hea.* TO 'hea'@'localhost'; > FLUSH PRIVILEGES; >3/ Fill the DB with some data > mysql hea < hea-app/sql/schema.sql > mysql hea < hea-app/sql/sql/mock-data.sql >4/ Checkout the 'v2' branch for both hea-ws and hea-app >5/ Execute the upgrade DB script > % cd hea-app > % perl -p -i -e 's/REPLACE_ME/hea/' sql/upgrade.pl # Fill the DB info > % perl sql/upgrade.pl >Now the DB is using the v2 structure. That means we have 1 installation >row per library previously defined. 1 library row has also been created. >5/ Configure hea-ws >% echo '192.168.50.1 hea.koha-community.org' >> /etc/hosts ><VirtualHost *:80> > DocumentRoot "/path/to/hea-ws" > ServerName "hea.koha-community.org" > <Directory "/"> > Options +ExecCGI > Require all granted > AddHandler cgi-script .pl > </Directory> ></VirtualHost> > >And enable it with a2ensite, then restart apache. >The copy the database.yml.sample to database.yml and edit it to fill the >DB info. > >6/ Launch the hea-app > % cd hea-app > % edit README.md # to install the missing modules > % cp environments/config.yml environments/development.yml > % edit environments/development.yml # to fill the DB info > % perl bin/app.pl >Then hit localhost:3000 >You should see a local version of Hea with sample data > >7/ Back to Koha side >A. We will test that the webservice still works with previous version of Koha (without v2) >a. Do not configure Hea > % perl misc/cronjobs/share_usage_with_koha_community.pl -f -v >Then hit localhost:3000 >=> Nothing added >b. Configure Hea on admin/usage_statistics.pl >perl misc/cronjobs/share_usage_with_koha_community.pl -f -v >=> New library added >c. Modify the Hea configuration >perl misc/cronjobs/share_usage_with_koha_community.pl -f -v >=> Info are modified > >B. Not we will test that it works with the new version (much more fun ;)) >% git checkout hea-v2 # koha >a. Configure Hea using /admin/usage_statistics.pl >perl misc/cronjobs/share_usage_with_koha_community.pl -f -v >=> Check the result on localhost:3000 >b. Share libraries's info >perl misc/cronjobs/share_usage_with_koha_community.pl -f -v >c. Continue to play a bit and share the info. > >Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz> >--- > C4/UsageStats.pm | 26 +++- > Koha/Schema/Result/Branch.pm | 12 +- > admin/usage_statistics.pl | 17 ++- > installer/data/mysql/atomicupdate/bug_18066.perl | 21 +++ > installer/data/mysql/sysprefs.sql | 3 + > koha-tmpl/intranet-tmpl/prog/en/modules/about.tt | 3 + > .../prog/en/modules/admin/preferences/admin.pref | 11 ++ > .../prog/en/modules/admin/usage_statistics.tt | 163 ++++++++++++++++++++- > misc/cronjobs/share_usage_with_koha_community.pl | 2 +- > t/db_dependent/UsageStats.t | 15 +- > 10 files changed, 257 insertions(+), 16 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_18066.perl > >diff --git a/C4/UsageStats.pm b/C4/UsageStats.pm >index cf8b98e..c71f99b 100644 >--- a/C4/UsageStats.pm >+++ b/C4/UsageStats.pm >@@ -23,6 +23,8 @@ use POSIX qw(strftime); > use LWP::UserAgent; > use JSON; > >+use Koha::Libraries; >+ > =head1 NAME > > C4::UsageStats >@@ -56,14 +58,24 @@ sub NeedUpdate { > } > > sub BuildReport { >- my $report = { >- library => { >- id => C4::Context->preference('UsageStatsID') || 0, >+ my $report; >+ my @libraries; >+ if( C4::Context->preference('UsageStatsLibrariesInfo') ) { >+ my $libraries = Koha::Libraries->search; >+ while ( my $library = $libraries->next ) { >+ push @libraries, { name => $library->branchname, url => $library->branchurl, country => $library->branchcountry, geolocation => $library->geolocation, }; >+ } >+ } >+ $report = { >+ installation => { >+ koha_id => C4::Context->preference('UsageStatsID') || 0, > name => C4::Context->preference('UsageStatsLibraryName') || q||, > url => C4::Context->preference('UsageStatsLibraryUrl') || q||, > type => C4::Context->preference('UsageStatsLibraryType') || q||, > country => C4::Context->preference('UsageStatsCountry') || q||, >+ geolocation => C4::Context->preference('UsageStatsGeolocation') || q||, > }, >+ libraries => \@libraries, > }; > > # Get database volumetry. >@@ -351,8 +363,12 @@ sub ReportToCommunity { > Content => $json, > ); > my $content = decode_json( $res->decoded_content ); >- C4::Context->set_preference( 'UsageStatsID', >- $content->{library}{id} ); >+ if ( $content->{koha_id} ) { >+ C4::Context->set_preference( 'UsageStatsID', $content->{koha_id} ); >+ } >+ if ( $content->{id} ) { >+ C4::Context->set_preference( 'UsageStatsPublicID', $content->{id} ); >+ } > } > > =head2 _count >diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm >index ec44cde..414b734 100644 >--- a/Koha/Schema/Result/Branch.pm >+++ b/Koha/Schema/Result/Branch.pm >@@ -128,6 +128,12 @@ __PACKAGE__->table("branches"); > data_type: 'text' > is_nullable: 1 > >+=head2 geolocation >+ >+ data_type: 'varchar' >+ is_nullable: 1 >+ size: 255 >+ > =cut > > __PACKAGE__->add_columns( >@@ -171,6 +177,8 @@ __PACKAGE__->add_columns( > { data_type => "mediumtext", is_nullable => 1 }, > "opac_info", > { data_type => "text", is_nullable => 1 }, >+ "geolocation", >+ { data_type => "varchar", is_nullable => 1, size => 255 }, > ); > > =head1 PRIMARY KEY >@@ -543,8 +551,8 @@ Composing rels: L</branchrelations> -> categorycode > __PACKAGE__->many_to_many("categorycodes", "branchrelations", "categorycode"); > > >-# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-10-24 13:56:21 >-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/9YwsU+GXK+fzc6IX2Tj5g >+# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-02-06 10:07:25 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aq4mf5Dwbd8ps9ANLy8DuQ > > > # You can replace this text with custom code or comments, and it will be preserved on regeneration >diff --git a/admin/usage_statistics.pl b/admin/usage_statistics.pl >index 4573321..01e002e 100755 >--- a/admin/usage_statistics.pl >+++ b/admin/usage_statistics.pl >@@ -21,6 +21,7 @@ use CGI qw ( -utf8 ); > use C4::Auth; > use C4::Output; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Libraries; > > my $query = new CGI; > my ( $template, $loggedinuser, $cookie ) = get_template_and_user( >@@ -42,12 +43,21 @@ if ( $op eq 'update' ) { > my $UsageStatsLibraryName = $query->param('UsageStatsLibraryName'); > my $UsageStatsLibraryType = $query->param('UsageStatsLibraryType'); > my $UsageStatsLibraryUrl = $query->param('UsageStatsLibraryUrl'); >+ my $UsageStatsLibrariesInfo = $query->param('UsageStatsLibrariesInfo'); >+ my $UsageStatsGeolocation = $query->param('UsageStatsGeolocation'); > C4::Context->set_preference('UsageStats', $UsageStats); > C4::Context->set_preference('UsageStatsCountry', $UsageStatsCountry); > C4::Context->set_preference('UsageStatsLibraryName', $UsageStatsLibraryName); > C4::Context->set_preference('UsageStatsLibraryType', $UsageStatsLibraryType); > C4::Context->set_preference('UsageStatsLibraryUrl', $UsageStatsLibraryUrl); >- >+ C4::Context->set_preference('UsageStatsLibrariesInfo', $UsageStatsLibrariesInfo); >+ C4::Context->set_preference('UsageStatsGeolocation', $UsageStatsGeolocation); >+ my $libraries = Koha::Libraries->search; >+ while ( my $library = $libraries->next ) { >+ if ( my $latlng = $query->param('geolocation_' . $library->branchcode) ) { >+ $library->geolocation( $latlng )->store; >+ } >+ } > } > > if ( C4::Context->preference('UsageStatsLastUpdateTime') ) { >@@ -55,4 +65,9 @@ if ( C4::Context->preference('UsageStatsLastUpdateTime') ) { > $template->param(UsageStatsLastUpdateTime => output_pref($dt) ); > } > >+my $libraries = Koha::Libraries->search; >+$template->param( >+ libraries => $libraries, >+); >+ > output_html_with_http_headers $query, $cookie, $template->output; >diff --git a/installer/data/mysql/atomicupdate/bug_18066.perl b/installer/data/mysql/atomicupdate/bug_18066.perl >new file mode 100644 >index 0000000..4ad2fc8 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_18066.perl >@@ -0,0 +1,21 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ unless( column_exists( 'branches', 'geolocation' ) ) { >+ $dbh->do(q| >+ ALTER TABLE branches ADD COLUMN geolocation VARCHAR(255) DEFAULT NULL after opac_info >+ |); >+ } >+ >+ $dbh->do(q| >+ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type ) VALUES ('UsageStatsGeolocation', '', NULL, 'Geolocation of the main library', 'Free'); >+ |); >+ $dbh->do(q| >+ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type ) VALUES ('UsageStatsLibrariesInfo', '', NULL, 'Share libraries information', 'YesNo'); >+ |); >+ $dbh->do(q| >+ INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type ) VALUES ('UsageStatsPublicID', '', NULL, 'Public ID for Hea website', 'Free'); >+ |); >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 18066 - Hea version 2)\n"; >+} >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index c9c86a2..10c3c40 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -538,10 +538,13 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('UsageStats', 0, NULL, 'Share anonymous usage data on the Hea Koha community website.', 'YesNo'), > ('UsageStatsCountry', '', NULL, 'The country where your library is located, to be shown on the Hea Koha community website', 'Choice'), > ('UsageStatsID', '', NULL, 'This preference is part of Koha but it should not be deleted or updated manually.', 'Free'), >+('UsageStatsGeolocation', '', NULL, 'Geolocation of the main library.', 'Free'), > ('UsageStatsLastUpdateTime', '', NULL, 'This preference is part of Koha but it should not be deleted or updated manually.', 'Free'), >+('UsageStatsLibrariesInfo', '', NULL, 'Share libraries information', 'YesNo'), > ('UsageStatsLibraryName', '', NULL, 'The library name to be shown on Hea Koha community website', 'Free'), > ('UsageStatsLibraryType', '', 'public|school|academic|research|private|societyAssociation|corporate|government|religiousOrg|subscription', 'The library type to be shown on the Hea Koha community website', 'Choice'), > ('UsageStatsLibraryUrl', '', NULL, 'The library URL to be shown on Hea Koha community website', 'Free'), >+('UsageStatsPublicID', '', NULL, 'Public ID for Hea website', 'Free'), > ('UseAuthoritiesForTracings','1','0','Use authority record numbers for subject tracings instead of heading strings.','YesNo'), > ('UseBranchTransferLimits','0','','If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.','YesNo'), > ('UseControlNumber','0','','If ON, record control number (w subfields) and control number (001) are used for linking of bibliographic records.','YesNo'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt >index 78e4b54..9d0cc3c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/about.tt >@@ -820,6 +820,9 @@ > > <h2>jquery.tablednd.js</h2> > <p>The <a href="https://github.com/isocra/TableDnD">TableDnD plug-in for jQuery</a> by Denis Howlett is licensed under the <a href="http://opensource.org/licenses/mit-license.php">MIT License</a>.</p> >+ >+ <h2>Leaflet</h2> >+ <p>The <a href="http://leafletjs.com">Leaflet</a> JavaScript library by Vladimir Agafonkinis licensed under the <a href="https://github.com/Leaflet/Leaflet/blob/master/LICENSE">BSD License</a>.</p> > </div> > > <div id="translations"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >index e9d95be..ba49128 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref >@@ -394,6 +394,17 @@ Administration: > religiousOrg: "religious organization" > subscription: "subscription" > - Note that this value has no effect if the UsageStats system preference is set to "Don't share" >+ - >+ - pref: UsageStatsLibrariesInfo >+ choices: >+ yes: "Share" >+ no: "Do not Share" >+ - "libraries information (name, url, country)" >+ - Note that this value has no effect if the UsageStats system preference is set to "Don't share" >+ - >+ - Geolocation of the main library: >+ - pref: UsageStatsGeolocation >+ - Note that this value has no effect if the UsageStats system preference is set to "Don't share" > Search Engine: > - > - "Use following search engine: " >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt >index 5da2693..756c239 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/usage_statistics.tt >@@ -5,6 +5,36 @@ > <title>Koha › Administration › Koha usage statistics</title> > [% INCLUDE 'doc-head-close.inc' %] > [% INCLUDE 'calendar.inc' %] >+<link rel="stylesheet" href="[% interface %]/lib/leaflet/leaflet.css" /> >+<script src="[% interface %]/lib/leaflet/leaflet.js"></script> >+ >+<script type="text/javascript"> >+//<![CDATA[ >+ var originalOffset; >+ $(window).scroll(function () { >+ var tbh = $("#mapid"); >+ var offsetTop = tbh.offset().top; >+ var s = parseInt($(window).scrollTop(), 10); >+ var fixMe = (s > offsetTop); >+ if ( !originalOffset ) originalOffset = tbh.position().top; >+ var repositionMe = (s < originalOffset); >+ if (fixMe) { >+ tbh.css({ >+ 'position': 'fixed', >+ 'top': '0', >+ 'margin-left': '40%' >+ }); >+ } >+ if (repositionMe) { >+ tbh.css({ >+ 'position': 'absolute', >+ 'top': originalOffset, >+ 'margin-left': '40%' >+ }); >+ } >+ }); >+//]]> >+</script> > </head> > > <body id="admin_usage_statistics" class="admin"> >@@ -48,7 +78,7 @@ > <form id="category_form" action="/cgi-bin/koha/admin/usage_statistics.pl" method="post"> > <h1>Modify the statistics you share with the Koha community</h1> > <fieldset class="rows"> >- <ol> >+ <ol style="float:left;"> > <li> > <label for="UsageStats">Share my Koha usage statistics: </label> > <select name="UsageStats" id="UsageStats"> >@@ -281,7 +311,7 @@ > </li> > <li> > <label for="UsageStatsLibraryName">Library name: </label> >- <input type="text" value="[% Koha.Preference('UsageStatsLibraryName') %]" name="UsageStatsLibraryName" id="UsageStatsLibraryName" /> >+ <input type="text" value="[% Koha.Preference('UsageStatsLibraryName') | html %]" name="UsageStatsLibraryName" id="UsageStatsLibraryName" /> > </li> > <li> > <label for="UsageStatsLibraryType">Library type: </label> >@@ -353,8 +383,58 @@ > Your data have never been shared > [% END %] > </li> >+ <li> >+ <label for="UsageStatsGeolocation">Geolocation: </label> >+ <input id="UsageStatsGeolocation" name="UsageStatsGeolocation" value="[% Koha.Preference('UsageStatsGeolocation') %]" type="text" value="[% Koha.Preference('UsageStatsLibrariesInfo') %]" size="35" readonly="readonly" /> >+ <a href="#" class="change_geolocation" data-branchname="" data-id="UsageStatsGeolocation"><img src="[% interface %]/lib/leaflet/images/marker-icon.png" title="Set geolocation" style="max-height: 2em;" /></a> >+ </li> >+ <li> >+ <label for="UsageStatsLibrariesInfo">Libraries informations: </label> >+ <select name="UsageStatsLibrariesInfo" id="UsageStatsLibrariesInfo"> >+ [% IF Koha.Preference('UsageStatsLibrariesInfo') %] >+ <option value="1" selected="selected">Yes</option> >+ <option value="0">No</option> >+ [% ELSE %] >+ <option value="1">Yes</option> >+ <option value="0" selected="selected">No</option> >+ [% END %] >+ </select> >+ </li> >+ >+ <li id="libraries_info"> >+ <fieldset class="rows"> >+ <legend>Libraries</legend> >+ <ol> >+ [% FOR l IN libraries %] >+ <li> >+ <label for="[% l.branchcode %]">[% l.branchname %]: </label> >+ <div style="float:left;"> >+ <div>Country: [% l.branchcountry %]</div> >+ <div>Url: [% l.branchurl %]</div> >+ <div> >+ Geolocation: <input type="text" id="geolocation_[% l.branchcode %]" name="geolocation_[% l.branchcode %]" value="[% l.geolocation %]" size="35" readonly="readonly" /> >+ <a href="#" class="change_geolocation" data-branchname="[% l.branchname %]" data-id="geolocation_[% l.branchcode %]"><img src="[% interface %]/lib/leaflet/images/marker-icon.png" title="Set geolocation for [% l.branchname %]" style="max-height: 2em;" /></a> >+ </div> >+ </div> >+ </li> >+ [% END %] >+ </ol> >+ </fieldset> >+ </li> >+ <li> >+ <label for="MyPublicLink">See your public page: </label> >+ [% IF Koha.Preference('UsageStatsPublicID') %] >+ [% SET my_url = 'http://hea.koha-community.org/libraries/' _ Koha.Preference('UsageStatsPublicID') %] >+ <a href="[% my_url %]">[% my_url %]</a> >+ [% ELSE %] >+ You do not have anything public yet. >+ [% END %] >+ </li> >+ > </ol> >- </fieldset> >+ <div style="clear:right"></div> >+ <div id="mapid" style="width: 600px; height: 400px; margin-left: 40%:"></div> >+ </fieldset> > > <fieldset class="action"> > <input type="hidden" name="op" value="update" /> >@@ -363,6 +443,83 @@ > </fieldset> > </form> > >+ <script> >+ var map = L.map('mapid').setView([0,0], 1); >+ L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', { >+ maxZoom: 18, >+ attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' + >+ '<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' + >+ 'Imagery © <a href="http://mapbox.com">Mapbox</a>', >+ id: 'mapbox.streets' >+ }).addTo(map); >+ >+ var default_elt = { 'text': _("Main library"), 'id': 'UsageStatsGeolocation' }; >+ var current_elt = default_elt; >+ >+ // Add the title >+ var title = L.control({position: 'topright'}); >+ title.onAdd = function (map) { >+ this._div = L.DomUtil.create('div', 'title'); >+ this.update(); >+ return this._div; >+ }; >+ title.update = function (props) { >+ this._div.innerHTML = '<h4>' + _("Click on the map to set the geolocation for %s").format(current_elt.text) + '</h4>'; >+ }; >+ title.addTo(map); >+ >+ var markers = {}; >+ function add_to_map(elt, latlng) { >+ var marker = markers[elt.id]; >+ if (marker) map.removeLayer(marker); >+ marker = L.marker(latlng).addTo(map); >+ marker.bindPopup(elt.text); >+ marker.on('mouseover', function (e) {this.openPopup(); }); >+ marker.on('mouseout', function (e) {this.closePopup();}); >+ markers[elt.id] = marker; >+ } >+ >+ // Init the map >+ [% IF Koha.Preference('UsageStatsGeolocation') %] >+ var latlng = [ [% Koha.Preference('UsageStatsGeolocation') %] ]; >+ add_to_map( current_elt, latlng ); >+ [% END %] >+ [% FOR l IN libraries %] >+ [% NEXT UNLESS l.geolocation %] >+ add_to_map( { 'text': "[% l.branchname %]", 'id': "geolocation_[% l.branchcode %]" }, [ [% l.geolocation %] ] ); >+ [% END %] >+ >+ // On click, update the geolocation and the marker >+ map.on('click', function(e){ >+ add_to_map( current_elt, e.latlng ); >+ $("#" + current_elt.id).val(e.latlng.lat + ',' + e.latlng.lng); >+ }); >+ >+ // Auto zoom >+ var group = new L.featureGroup(Object.keys(markers).map(function(key){return markers[key]})); >+ if ( group.getBounds().isValid() ) map.fitBounds(group.getBounds()); >+ >+ // On click on the marker icons, update the title of the map >+ $(document).ready(function(){ >+ $(".change_geolocation").on('click', function(e){ >+ e.preventDefault(); >+ if ( $(this).data('branchname') ) { >+ current_elt = { 'text': $(this).data('branchname'), 'id': $(this).data('id') }; >+ } else { >+ current_elt = default_elt; >+ } >+ title.update(); >+ }); >+ $("#UsageStatsLibrariesInfo").change(); >+ }); >+ >+ $("#UsageStatsLibrariesInfo").on('change', function(){ >+ if ( $(this).val() == 1 ) $("#libraries_info").show() >+ else $("#libraries_info").hide(); >+ }); >+ >+ </script> >+ > </div> > </div> > <div class="yui-b"> >diff --git a/misc/cronjobs/share_usage_with_koha_community.pl b/misc/cronjobs/share_usage_with_koha_community.pl >index 16de62a..9039558 100755 >--- a/misc/cronjobs/share_usage_with_koha_community.pl >+++ b/misc/cronjobs/share_usage_with_koha_community.pl >@@ -70,7 +70,7 @@ Only the total number is retrieved. In no case will private data be shared! > > In order to know which parts of Koha modules are used, this script will collect some system preference values. > >-If you want to tell us who you are, you can fill the UsageStatsLibraryName system preference with your library name, UsageStatsLibraryUrl, UsageStatsLibraryType and/or UsageStatsCountry. >+If you want to tell us who you are, you can fill the UsageStatsLibraryName system preference with your library name, UsageStatsLibraryUrl, UsageStatsLibraryType and/or UsageStatsCountry, UsageStatsLibrariesInfo. > > All these data will be analyzed on the http://hea.koha-community.org Koha community website. > >diff --git a/t/db_dependent/UsageStats.t b/t/db_dependent/UsageStats.t >index 7f5d543..33af62d 100644 >--- a/t/db_dependent/UsageStats.t >+++ b/t/db_dependent/UsageStats.t >@@ -15,11 +15,13 @@ > # with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >-use Test::More tests => 57; >+use Test::More tests => 59; > use t::lib::Mocks qw(mock_preference); > use POSIX qw(strftime); > use Data::Dumper; > >+use Koha::Libraries; >+ > BEGIN { > use_ok('C4::UsageStats'); > use_ok('C4::Context'); >@@ -78,20 +80,22 @@ is( $update, 0, "Last update just be done, no update needed " ); > #mock to 0 > t::lib::Mocks::mock_preference( "UsageStatsID", 0 ); > t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 0 ); >-t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); >+t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 0 ); > t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 0 ); > t::lib::Mocks::mock_preference( "UsageStatsCountry", 0 ); >+t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 0 ); > > my $report = C4::UsageStats->BuildReport(); > > isa_ok( $report, 'HASH', '$report is a HASH' ); > isa_ok( $report->{library}, 'HASH', '$report->{library} is a HASH' ); >-is( scalar( keys %{$report->{library}} ), 5, "There are 5 fields in $report->{library}" ); >+is( scalar( keys %{$report->{library}} ), 6, "There are 6 fields in $report->{library}" ); > is( $report->{library}->{id}, 0, "UsageStatsID is good" ); > is( $report->{library}->{name}, '', "UsageStatsLibraryName is good" ); > is( $report->{library}->{url}, '', "UsageStatsLibraryUrl is good" ); > is( $report->{library}->{type}, '', "UsageStatsLibraryType is good" ); > is( $report->{library}->{country}, '', "UsageStatsCountry is good" ); >+is( $report->{library}->{number_of_libraries}, undef, "UsageStatsLibrariesInfo is good" ); > > #mock with values > t::lib::Mocks::mock_preference( "UsageStatsID", 1 ); >@@ -99,17 +103,20 @@ t::lib::Mocks::mock_preference( "UsageStatsLibraryName", 'NAME' ); > t::lib::Mocks::mock_preference( "UsageStatsLibraryUrl", 'URL' ); > t::lib::Mocks::mock_preference( "UsageStatsLibraryType", 'TYPE' ); > t::lib::Mocks::mock_preference( "UsageStatsCountry", 'COUNTRY' ); >+t::lib::Mocks::mock_preference( "UsageStatsLibrariesInfo", 1 ); > > $report = C4::UsageStats->BuildReport(); > > isa_ok( $report, 'HASH', '$report is a HASH' ); > isa_ok( $report->{library}, 'HASH', '$report->{library} is a HASH' ); >-is( scalar( keys %{$report->{library}} ), 5, "There are 5 fields in $report->{library}" ); >+is( scalar( keys %{$report->{library}} ), 6, "There are 6 fields in $report->{library}" ); > is( $report->{library}->{id}, 1, "UsageStatsID is good" ); > is( $report->{library}->{name}, 'NAME', "UsageStatsLibraryName is good" ); > is( $report->{library}->{url}, 'URL', "UsageStatsLibraryUrl is good" ); > is( $report->{library}->{type}, 'TYPE', "UsageStatsLibraryType is good" ); > is( $report->{library}->{country}, 'COUNTRY', "UsageStatsCountry is good" ); >+my $nb_of_libraries = Koha::Libraries->count; >+is( $report->{library}->{number_of_libraries}, $nb_of_libraries, "UsageStatsLibrariesInfo is good" ); > > #Test report->volumetry --------------- > #with original values >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18066
:
59975
|
59976
|
60729
|
60730
|
60734
|
60742
|
60743
|
60744
|
60745
|
60746
|
61355
|
61356
|
61358
|
61361
|
61362
|
61392
|
61393
|
61394
|
61395
|
61396
|
61397
|
61398
|
61427
|
61428
|
61429
|
61430
|
61431
|
61432
|
61433
|
61582
|
62646