Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #259 from Callek/issue259
Browse files Browse the repository at this point in the history
  • Loading branch information
Callek committed Jun 15, 2015
2 parents d9aa7a9 + 643a1f5 commit cca7b2f
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 25 deletions.
15 changes: 13 additions & 2 deletions relengapi/blueprints/slaveloan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
from flask import Blueprint
from flask import g
from flask import render_template
from flask import url_for
from flask.ext.login import current_user
from relengapi import apimethod
from relengapi import p
from relengapi.blueprints.slaveloan import task_groups
from relengapi.blueprints.slaveloan.slave_mappings import slave_patterns
from relengapi.blueprints.slaveloan.slave_mappings import slave_to_slavetype
from relengapi.lib import angular
from relengapi.lib import api
from relengapi.util import tz
from werkzeug.exceptions import BadRequest
from werkzeug.exceptions import InternalServerError
Expand Down Expand Up @@ -162,12 +165,15 @@ def new_loan_from_admin(body):


@bp.route('/loans/request', methods=['POST'])
@p.slaveloan.admin.require()
@apimethod(rest.Loan, body=rest.LoanRequest)
def new_loan_request(body):
"User Loan Requesting, returns the id of the loan"
if not body.ldap_email:
raise BadRequest("Missing LDAP E-Mail")
if not p.slaveloan.admin.can():
if not body.ldap_email == current_user.authenticated_email:
raise BadRequest("You can't request loans on behalf of others.")

if not body.requested_slavetype:
raise BadRequest("Missing slavetype")

Expand Down Expand Up @@ -288,7 +294,12 @@ def update_loan_action(action_id, body):
@bp.route('/')
@flask_login.login_required
def root():
return render_template('slaveloan_root.html')
return angular.template(
'slaveloan_root.html',
url_for('.static', filename='slaveloan_root.js'),
machine_types=api.get_data(get_machine_classes),
loan_request_url=url_for("slaveloan.new_loan_request"),
)


@bp.route('/details/<int:id>')
Expand Down
46 changes: 46 additions & 0 deletions relengapi/blueprints/slaveloan/static/slaveloan_root.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<div ng-app="slaveloan" ng-controller="slaveloanController">
<h2>New Loan</h2>

<form name="newLoanForm">
<fieldset><legend>Who You Are</legend>
<div class="form-group">
<label for="ldap_email" class="control-label col-sm-2">Full LDAP Username: </label>
<div class="col-sm-4">
<input type="text" ng-model="newLoan.ldap_email" name="ldap_email" class="form-control" disabled />
</div>
</div>
<div class="form-group">
<label for="bugzilla_email" class="control-label col-sm-2">Your Bugzilla E-mail: </label>
<div class="col-sm-4">
<input type="text" name="bugzilla_email" ng-model="newLoan.bugzilla_email" class="form-control" placeholder="{{user}}" />
</div>
</div>
</fieldset>

<fieldset><legend>Slave Info</legend>
<div class="form-group">
<label for="slave2loan" class="control-label col-sm-2">Slave to loan: </label>
<div class="col-sm-3">
<select name="slave2loan" class="form-control" ng-model="newLoan.slavetype" ng-required="true">
<option></option>
<option ng-repeat="(key, value) in machineTypes">{{key}}</option>
</select>
</div>
</div>
<div class="alert alert-info col-xs-12" role="alert">
If you don't know what machine you need either ping us for help in
<a href="irc://irc.mozilla.org/#releng">#releng
<span class="glyphicon glyphicon-new-window"></span></a>
or file a <a href="http://bugzil.la/foo">bug
<span class="glyphicon glyphicon-new-window"></span></a> instead,
</div>
<fieldset>

<legend>Complete</legend>
<button class="btn btn-primary btn-block" ng-disabled="addSlaveForm.$invalid" ng-click="submitLoanRequest()">Submit Loan Request</button>
</fieldset>
</form>
</div>
48 changes: 48 additions & 0 deletions relengapi/blueprints/slaveloan/static/slaveloan_root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

angular.module('slaveloan', ['relengapi', 'initial_data']);

angular.module('slaveloan').controller('slaveloanController',
function($scope, restapi, initial_data) {
$scope.machineTypes = initial_data.machine_types;
$scope.user = initial_data.user.authenticated_email;
$scope.loanRequestUrl = initial_data.loan_request_url;

$scope.newLoan = {
ldap_email: $scope.user,
bugzilla_email: '',
slavetype: '',
};

$scope.origNewLoan = angular.copy($scope.newLoan);

$scope.submitLoanRequest = function() {
var ldap = $scope.newLoan.ldap_email;
var bugzilla = $scope.newLoan.bugzilla_email;
var slavetype = $scope.newLoan.slavetype;

restapi({
url: $scope.loanRequestUrl,
method: 'POST',
headers: {'Content-Type': 'application/json; charset=utf-8'},
data: JSON.stringify({
ldap_email: ldap,
bugzilla_email: bugzilla,
requested_slavetype: slavetype,
}),
while: 'Submitting Loan Request',
}).then(function(response) {
if (response.data.result) {
var r = response.data.result;
$scope.newLoan = angular.copy($scope.origNewLoan);
$scope.newLoanForm.$setPristine();
alertify.success("Loan id " + r.id + " successfully filed")
} else {
alertify.error("Error submitting loan");
}
});
};

});
23 changes: 0 additions & 23 deletions relengapi/blueprints/slaveloan/templates/slaveloan_root.html

This file was deleted.

0 comments on commit cca7b2f

Please sign in to comment.