Kouhei Sutou
null+****@clear*****
Wed Dec 31 23:18:33 JST 2014
Kouhei Sutou 2014-12-31 23:18:33 +0900 (Wed, 31 Dec 2014) New Revision: 6fc4ca5c9b835af4231d16dd001d356d11525de7 https://github.com/groonga/groonga-admin/commit/6fc4ca5c9b835af4231d16dd001d356d11525de7 Message: tables: support creating a simple table Added files: app/scripts/controllers/table-new-controller.js app/views/tables/new.html Modified files: app/index.html app/scripts/app.js app/styles/main.scss app/views/tables/index.html Modified: app/index.html (+1 -0) =================================================================== --- app/index.html 2014-12-31 23:18:00 +0900 (2e1f2ae) +++ app/index.html 2014-12-31 23:18:33 +0900 (e6279a5) @@ -86,6 +86,7 @@ <script src="scripts/controllers/top-controller.js"></script> <script src="scripts/controllers/table-index-controller.js"></script> <script src="scripts/controllers/table-show-controller.js"></script> + <script src="scripts/controllers/table-new-controller.js"></script> <script src="scripts/controllers/table-search-controller.js"></script> <script src="scripts/controllers/column-show-controller.js"></script> <!-- endbuild --> Modified: app/scripts/app.js (+4 -0) =================================================================== --- app/scripts/app.js 2014-12-31 23:18:00 +0900 (fa0de22) +++ app/scripts/app.js 2014-12-31 23:18:33 +0900 (32c8864) @@ -29,6 +29,10 @@ angular templateUrl: 'views/tables/index.html', controller: 'TableIndexController' }) + .when('/tables/_new', { + templateUrl: 'views/tables/new.html', + controller: 'TableNewController' + }) .when('/tables/:table/', { templateUrl: 'views/tables/show.html', controller: 'TableShowController' Added: app/scripts/controllers/table-new-controller.js (+68 -0) 100644 =================================================================== --- /dev/null +++ app/scripts/controllers/table-new-controller.js 2014-12-31 23:18:33 +0900 (80005de) @@ -0,0 +1,68 @@ +'use strict'; + +/** + * @ngdoc function + * @name groongaAdminApp.controller:TableNewController + * @description + * # TableNewController + * Controller of the groongaAdminApp + */ +angular.module('groongaAdminApp') + .controller('TableNewController', [ + '$scope', '$http', '$location', 'schemaLoader', + function ($scope, $http, $location, schemaLoader) { + var schema; + var client = new GroongaClient($http); + + function initialize() { + $scope.availableTypes = { + array: { + label: 'Array', + flag: 'TABLE_NO_KEY' + }, + hashTable: { + label: 'Hash table', + flag: 'TABLE_HASH_KEY' + }, + patriciaTrie: { + label: 'Patricia trie', + flag: 'TABLE_PAT_KEY' + }, + doubleArrayTrie: { + label: 'Double array trie', + flag: 'TABLE_DAT_KEY' + } + }; + $scope.parameters = { + type: $scope.availableTypes.array + }; + $scope.tables = { + }; + $scope.submit = submit; + } + + function submit() { + var parameters = { + name: $scope.parameters.name, + flags: [$scope.parameters.type.flag].join('|') + }; + var request = client.execute('table_create', parameters); + request.success(function(response) { + if (response.isCreated()) { + schemaLoader().reload(); + $location.url('/tables/' + parameters.name); + } else { + var errorMessage = response.errorMessage(); + $scope.message = 'Failed to create table: ' + errorMessage; + } + }); + } + + initialize(); + schemaLoader() + .then(function(_schema) { + schema = _schema; + + $scope.tables = schema.tables; + }); + }]); Modified: app/styles/main.scss (+23 -0) =================================================================== --- app/styles/main.scss 2014-12-31 23:18:00 +0900 (86ccf2b) +++ app/styles/main.scss 2014-12-31 23:18:33 +0900 (ed450fd) @@ -74,6 +74,29 @@ $icon-font-path: "../bower_components/bootstrap-sass-official/assets/fonts/boots } } +.table-form { + @extend .form-horizontal; + + label { + @extend .col-md-1; + } + + input, + select { + @extend .col-md-11; + } + + .form-button { + @extend .col-md-offset-1; + @extend .col-md-11; + } + + button[type=submit] { + @extend .btn; + @extend .btn-default; + } +} + /* Responsive: Portrait tablets and up */ @media screen and (min-width: 768px) { /* Remove the padding we set earlier */ Modified: app/views/tables/index.html (+8 -1) =================================================================== --- app/views/tables/index.html 2014-12-31 23:18:00 +0900 (58446b8) +++ app/views/tables/index.html 2014-12-31 23:18:33 +0900 (aeab9c3) @@ -9,7 +9,14 @@ <p>{{message}}</p> </div> - <h2>Tables</h2> + <h2> + Tables + <a href="#/tables/_new" title="Create a table"> + <span class="badge"> + <span class="glyphicon glyphicon-plus"></span> + </span> + </a> + </h2> <div class="tables"> <table> <thead> Added: app/views/tables/new.html (+81 -0) 100644 =================================================================== --- /dev/null +++ app/views/tables/new.html 2014-12-31 23:18:33 +0900 (37fc407) @@ -0,0 +1,81 @@ +<div class="container-fluid" ng-controller="TableNewController"> + <ol class="breadcrumb"> + <li><a href="#/">Top</a></li> + <li class="active"><a href="#/tables/">Tables</a></li> + </ol> + + <div class="content"> + <div class="alert alert-warning" ng-show="message.length > 0"> + <p>{{message}}</p> + </div> + + <h2>Create a new table</h2> + <form name="tableForm" class="table-form" ng-submit="submit()"> + <div class="form-group" + ng-class="{'has-error': tableForm.name.$invalid}"> + <label for="name" class="control-label">Name</label> + <input id="name" + name="name" + type="text" + class="form-control" + ng-model="parameters.name" + required> + </div> + <div class="form-group" + ng-class="{'has-error': tableForm.type.$invalid}"> + <label for="type" class="control-label">Type</label> + <select id="type" + name="type" + type="select" + class="form-control" + ng-model="parameters.type" + ng-options="type.label for (name, type) in availableTypes"> + </select> + </div> + <div class="form-group" + ng-class="{'has-error': tableForm.keyType.$invalid}"> + <label for="key-type" class="control-label">Key type</label> + <input id="key-type" + name="keyType" + type="text" + class="form-control" + ng-model="parameters.keyType" + ng-disabled="parameters.type === availableTypes.array"> + </div> + <!-- + <div class="form-group" + ng-class="{'has-error': tableForm.normalizer.$invalid}"> + <label for="normalizer" class="control-label">Normalizer</label> + <input id="normalizer" + name="normalizer" + class="form-control" + type="text" + ng-model="parameters.normalizer"> + </div> + <div class="form-group" + ng-class="{'has-error': tableForm.tokenizer.$invalid}"> + <label for="tokenizer" class="control-label">Tokenizer</label> + <input id="tokenizer" + name="tokenizer" + type="text" + class="form-control" + ng-model="parameters.tokenizer"> + </div> + <div class="form-group" + ng-class="{'has-error': tableForm.tokenFilteres.$invalid}"> + <label for="token-filters" class="control-label">Token filters</label> + <input id="token-filters" + name="tokenFilters" + type="text" + class="form-control" + ng-model="parameters.tokenFilters"> + </div> + --> + <div class="form-group"> + <div class="form-button"> + <button type="submit">Submit</button> + </div> + </div> + </form> + </div> +</div> -------------- next part -------------- HTML����������������������������...Download