Madhuvishy has uploaded a new change for review. https://gerrit.wikimedia.org/r/254887
Change subject: [WIP] Add new form for launching the global metrics report ...................................................................... [WIP] Add new form for launching the global metrics report Change-Id: I58091cc0c8f41a26d8021e4b3a5a8595993fca31 --- A wikimetrics/forms/global_metrics_form.py A wikimetrics/static/js/globalReportUpload.js M wikimetrics/static/js/reportCreate.js M wikimetrics/static/js/site.js A wikimetrics/templates/forms/global_report_upload.html A wikimetrics/templates/global_reports.html 6 files changed, 144 insertions(+), 17 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/analytics/wikimetrics refs/changes/87/254887/1 diff --git a/wikimetrics/forms/global_metrics_form.py b/wikimetrics/forms/global_metrics_form.py new file mode 100644 index 0000000..d5dcfce --- /dev/null +++ b/wikimetrics/forms/global_metrics_form.py @@ -0,0 +1,26 @@ +import uuid + +from flask import g +from wikimetrics.configurables import db +from wtforms import HiddenField +from wikimetrics.forms.fields import BetterBooleanField, BetterDateTimeField +from wtforms.validators import Required +from wikimetrics.forms.validators import NotGreater +from wikimetrics.utils import parse_username, thirty_days_ago, today, format_pretty_date +from cohort_upload import CohortUpload +from validators import ( + CohortNameUnused, CohortNameLegalCharacters, ProjectExists, RequiredIfNot +) + + +class GlobalMetricsForm(CohortUpload): + """ + Defines the fields necessary to upload inputs to calculate + the global metrics + """ + # Override cohort name, validate_as_user_ids and centralauth + # The user for the Global API doesn't have to define these + name = HiddenField(default='GlobalCohort_' + str(uuid.uuid1())) + start_date = BetterDateTimeField( + default=thirty_days_ago, validators=[NotGreater('end_date')]) + end_date = BetterDateTimeField(default=today) diff --git a/wikimetrics/static/js/globalReportUpload.js b/wikimetrics/static/js/globalReportUpload.js new file mode 100644 index 0000000..f1693f7 --- /dev/null +++ b/wikimetrics/static/js/globalReportUpload.js @@ -0,0 +1,8 @@ +$(document).ready(function(){ + + ko.applyBindings({ + // Timezone list and defaults + availableTimezones : ko.observableArray(site.availableTimezones), + timezone: ko.observable(site.utcTimezone), + }); +}); diff --git a/wikimetrics/static/js/reportCreate.js b/wikimetrics/static/js/reportCreate.js index 2f9fb46..941a43c 100644 --- a/wikimetrics/static/js/reportCreate.js +++ b/wikimetrics/static/js/reportCreate.js @@ -51,8 +51,7 @@ }); } - var utcTimezone = {name: 'UTC', value: '+00:00'}, - viewModel = { + var viewModel = { filter: ko.observable(''), cohorts: ko.observableArray([]), @@ -69,20 +68,9 @@ return true; }, - // Add more timezones as necessary - availableTimezones : ko.observableArray([ - {name: 'Central European Time', value: '+01:00'}, - {name: 'Eastern European Time', value: '+02:00'}, - {name: 'East Australian Standard Time', value: '+10:00'}, - utcTimezone, - {name: 'Atlantic Standard Time', value: '-04:00'}, - {name: 'Eastern Standard Time', value: '-05:00'}, - {name: 'Central Standard Time', value: '-06:00'}, - {name: 'Mountain Standard Time', value: '-07:00'}, - {name: 'Pacific Standard Time', value: '-08:00'}, - {name: 'Hawaii Standard Time', value: '-10:00'} - ]), - timezone: ko.observable(utcTimezone), + // Timezone list and defaults + availableTimezones : ko.observableArray(site.availableTimezones), + timezone: ko.observable(site.utcTimezone), // global metric defaults, by property defaults: { diff --git a/wikimetrics/static/js/site.js b/wikimetrics/static/js/site.js index f1f8c38..9326663 100644 --- a/wikimetrics/static/js/site.js +++ b/wikimetrics/static/js/site.js @@ -176,7 +176,26 @@ isEmpty: function(obj){ var empty = JSON.stringify(obj) === "{}"; return empty - } + }, + + // *********************************************************** + // List of timezones and default timezone + // *********************************************************** + utcTimezone: {name: 'UTC', value: '+00:00'}, + + // Add more timezones as necessary + availableTimezones : [ + {name: 'Central European Time', value: '+01:00'}, + {name: 'Eastern European Time', value: '+02:00'}, + {name: 'East Australian Standard Time', value: '+10:00'}, + {name: 'UTC', value: '+00:00'}, + {name: 'Atlantic Standard Time', value: '-04:00'}, + {name: 'Eastern Standard Time', value: '-05:00'}, + {name: 'Central Standard Time', value: '-06:00'}, + {name: 'Mountain Standard Time', value: '-07:00'}, + {name: 'Pacific Standard Time', value: '-08:00'}, + {name: 'Hawaii Standard Time', value: '-10:00'}, + ] }; /* diff --git a/wikimetrics/templates/forms/global_report_upload.html b/wikimetrics/templates/forms/global_report_upload.html new file mode 100644 index 0000000..e75bb9b --- /dev/null +++ b/wikimetrics/templates/forms/global_report_upload.html @@ -0,0 +1,75 @@ +{% import 'forms/field_validation.html' as validation %} + +<form enctype="multipart/form-data" + action="{{url_for('global_reports_request')}}" + method="POST" + class="upload-cohort form-horizontal"> + + {{ form.csrf_token }} + + <div class="navbar-inner"> + <h3>Launch a global report</h3> + </div> + <input id="name" name="name" type="hidden" value="{{form.name.data}}"> + <input id="centralauth" type="hidden" name="centralauth" checked value="{{form.centralauth.data}}"> + + <div class="control-group"> + <label for="project" class="control-label">Default Project</label> + <div class="controls"> + <input type="text" name="project" id="project" + value="{{form.project.data or ''}}" + data-provide="typeahead" + data-source='{{projects}}' + autocomplete="off" + /> + {{ validation.messages(form.project) }} + </div> + </div> + <div class="control-group"> + <label for="paste_ids_or_names" class="control-label" title="See below for format information"><strong>Paste User Names</strong></label> + <div class="controls"> + <textarea name="paste_ids_or_names" id="paste_ids_or_names" + rows="4" + cols="50">{{form.paste_ids_or_names.data or ''}}</textarea> + {{ validation.messages(form.paste_ids_or_names) }} + </div> + </div> + + <div class="control-group"> + <label for="timezone" class="control-label">Timezone</label> + <div class="controls"> + <select name="timezone" id="timezone" + data-bind=" + options: availableTimezones, + optionsText: function (item) { + return item.value + ' ' + item.name; + }, + value: timezone"></select> + </div> + </div> + <div class="control-group"> + <label class="control-label" for="start_date">Start Date</label> + <div class="controls"> + <div data-bind="datetimepicker: { + timezone: timezone, + value: ko.observable('{{form.start_date.data}}'), + inputId: 'start_date' + }"> + </div> + </div> + </div> + <div class="control-group"> + <label class="control-label" for="end_date">End Date / As of Date</label> + <div class="controls"> + <div data-bind="datetimepicker: { + timezone: timezone, + value: ko.observable('{{form.end_date.data}}'), + inputId: 'end_date' + }"> + </div> + </div> + </div> + <div class="form-actions"> + <input type="submit" class="btn btn-primary" value="Launch Global Report"/> + </div> +</form> \ No newline at end of file diff --git a/wikimetrics/templates/global_reports.html b/wikimetrics/templates/global_reports.html new file mode 100644 index 0000000..9a60a27 --- /dev/null +++ b/wikimetrics/templates/global_reports.html @@ -0,0 +1,11 @@ +{% extends "layout.html" %} +{% block body %} +{% include "forms/global_report_upload.html" %} +{% endblock %} + +{% block scripts %} +<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script> +<script src="{{ url_for('static', filename='js/bootstrap-datetimepicker.min.js') }}"></script> +<script src="{{ url_for('static', filename='js/cohortUpload.js') }}"></script> +<script src="{{ url_for('static', filename='js/globalReportUpload.js') }}"></script> +{% endblock %} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/254887 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I58091cc0c8f41a26d8021e4b3a5a8595993fca31 Gerrit-PatchSet: 1 Gerrit-Project: analytics/wikimetrics Gerrit-Branch: master Gerrit-Owner: Madhuvishy <mviswanat...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits