Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/survey_server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-07-13 12:15:08 +0300
committerBjoern Schiessle <schiessle@owncloud.com>2015-07-15 13:14:24 +0300
commitdb68602720cd62fc34cf61cfc472055978c4ad47 (patch)
tree12c023b2454f71ae06ccd60c42cbfae28be90811 /js
parent7d2266e668751170ee935d6d90259f8fffc91493 (diff)
first basic version of the popularity contest server app
Diffstat (limited to 'js')
-rw-r--r--js/script.js143
1 files changed, 125 insertions, 18 deletions
diff --git a/js/script.js b/js/script.js
index f0e54fc..30d9332 100644
--- a/js/script.js
+++ b/js/script.js
@@ -1,31 +1,138 @@
/**
- * ownCloud - popularitycontestserver
+ * @author Björn Schießle <schiessle@owncloud.com>
*
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
+ * @copyright Copyright (c) 2015, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
*
- * @author Bjoern Schiessle <schiessle@owncloud.com>
- * @copyright Bjoern Schiessle 2015
*/
(function ($, OC) {
$(document).ready(function () {
- $('#hello').click(function () {
- alert('Hello from your script file');
- });
-
- $('#echo').click(function () {
- var url = OC.generateUrl('/apps/popularitycontestserver/echo');
- var data = {
- echo: $('#echo-content').val()
+
+ /**
+ * calculate random color for the charts
+ * @returns {string}
+ */
+ var getRandomColor = function() {
+ var letters = '0123456789ABCDEF'.split('');
+ var color = '#';
+ for (var i = 0; i < 6; i++ ) {
+ color += letters[Math.floor(Math.random() * 16)];
+ }
+ return color;
+ };
+
+ /**
+ * add general statistics to the page
+ * @param instances how many instances are counted
+ * @param users statistics about the users
+ */
+ var showGeneralStatistics = function(instances, users) {
+ $('#instances span').text(instances);
+ $('#maxUsers span').text(users['max']);
+ $('#minUsers span').text(users['min']);
+ $('#averageUsers span').text(users['average']);
+ };
+
+ /**
+ * draw the chart of enabled apps
+ *
+ * @param array data
+ */
+ var appsChart = function (data) {
+ var appLabels = new Array();
+ var appValues = new Array();
+ for (key in data) {
+ appLabels.push(key);
+ appValues.push(data[key]);
+ }
+
+ var appData = {
+ labels: appLabels,
+ datasets: [
+ {
+ label: "Enabled Apps",
+ fillColor: "rgba(151,187,205,0.5)",
+ strokeColor: "rgba(151,187,205,0.8)",
+ highlightFill: "rgba(151,187,205,0.75)",
+ highlightStroke: "rgba(151,187,205,1)",
+ data: appValues
+ }
+ ]
};
- $.post(url, data).success(function (response) {
- $('#echo-result').text(response.echo);
- });
+ var ctx = document.getElementById("appChart").getContext("2d");
+ var myBarChart = new Chart(ctx).Bar(appData);
+ };
+
+ /**
+ * draw the chart of php versions
+ *
+ * @param array data
+ */
+ var phpVersionsChart = function (data) {
+ var phpVersionsData = new Array();
+ for (key in data) {
+ phpVersionsData.push(
+ {
+ value: data[key],
+ color: getRandomColor(),
+ label: 'PHP ' + key
+ }
+ );
+
+ }
+ var ctx = document.getElementById("phpChart").getContext("2d");
+ var myPieChart = new Chart(ctx).Pie(phpVersionsData);
+
+ };
+
+ /**
+ * draw the chart of ownCloud versions
+ *
+ * @param array data
+ */
+ var ocVersionsChart = function (data) {
+ var ocVersionsData = new Array();
+ for (key in data) {
+ ocVersionsData.push(
+ {
+ value: data[key],
+ color: getRandomColor(),
+ label: 'ownCloud ' + key
+ }
+ );
+
+ }
+ var ctx = document.getElementById("ocVersionChart").getContext("2d");
+ var myPieChart = new Chart(ctx).Pie(ocVersionsData);
+
+ };
+
+ $.get(
+ OC.generateUrl('/apps/popularitycontestserver/api/v1/data'), {}
+ ).done(
+ function (data) {
+ showGeneralStatistics(data['instances'], data['users']);
+ appsChart(data['apps']);
+ phpVersionsChart(data['system']['phpversion']);
+ ocVersionsChart(data['system']['ocversion']);
+ }
+ );
- });
});
-})(jQuery, OC); \ No newline at end of file
+})(jQuery, OC);