get '/:database/_design/:design/_view/:view' => sub {
my $self = shift;
+ my $format = $self->param('format');
my $url = join('/', $self->param('database'),'_design',$self->param('design'),'_view',$self->param('view') );
- my $param = $self->req->url->query->clone->remove('callback')->to_string;
- $url .= '?' . $param if $param;
+ if ( my $param = $self->req->url->query->clone->remove('callback')->remove('format')->to_string ) {
+ $url .= '?' . $param
+ }
warn "CouchDB proxy $url";
- _render_jsonp( $self, _couchdb_get($url));
+ my $json = _couchdb_get($url);
+ if ( $format eq 'key_array' ) { # array of keys sorted by value
+ $json->{rows} = [ map { $_->{key} } sort { $b->{value} <=> $a->{value} } @{ $json->{rows} } ];
+ }
+ _render_jsonp( $self, $json );
+};
+
+# http://showmetheco.de/articles/2010/10/adding-etag-caching-to-your-mojolicious-app.html
+
+hook after_dispatch => sub {
+ my $self = shift;
+
+ return unless $self->req->method eq 'GET';
+
+ my $body = $self->res->body;
+ return unless defined $body;
+
+ return if $self->res->headers->header('ETag');
+
+ my $our_etag = Mojo::ByteStream->new($body)->md5_sum;
+ $self->res->headers->header('ETag' => $our_etag);
+
+ my $browser_etag = $self->req->headers->header('If-None-Match');
+ return unless $browser_etag && $browser_etag eq $our_etag;
+
+ $self->app->log->info("HTTP cache hit ", dump( $self->req->url->to_string ), $our_etag );
+
+ $self->res->code(304);
+ $self->res->body('');
};
+
app->start;
<!--
<div>Angular seed app: v<span app-version></span></div>
-->
+ <script src="/lib/jquery/1.8.3/jquery.min.js"></script>
+ <script src="/lib/bootstrap/js/bootstrap.min.js"></script>
<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
-->
<script src="/lib/angular/angular.js"></script>
<script src="/lib/angular/angular-resource.js"></script>
+ <script src="/lib/angular-strap/dist/angular-strap.min.js"></script>
<script src="/js/app.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
// Declare app level module which depends on filters, and services
-angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives']).
+angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', '$strap.directives' ]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/registration/:registrationId', {templateUrl: 'partials/registration.html', controller: RegistrationCtrl});
$routeProvider.when('/confirmation/:registrationId', {templateUrl: 'partials/confirmation.html', controller: RegistrationCtrl});
/* Controllers */
-function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route) {
+function RegistrationCtrl($scope, $log, Registration, $routeParams, $location, $route, View) {
$scope.$routeParams = $routeParams;
$scope.$location = $location;
+ $scope.organizations = [];
$scope.update = function(registration) {
}
$log.info( $routeParams.registrationId );
+
+ $scope.view = new View();
+if(1){//FIXME
+ $scope.view.$get({ view: 'organizations' }, function(result) {
+ $log.info('View organizations', result);
+ angular.forEach( result.rows, function(value, key) {
+ this.push( value.key ); // name of organization
+ }, $scope.organizations );
+ $log.info('organizations', $scope.organizations);
+ });
+}else{//FIXME
+ $scope.view.$key_array({ view: 'organizations' }, function(result) {
+ $log.info('key_array', result);
+ $scope.organizations = result.rows;
+ $log.info('organizations', $scope.organizations);
+ });
}
+}//FIXME
$scope.$watch('user.registration_type', function( oldValue, newValue ) {
$log.info("registration_type watch", oldValue, newValue );
return $resource('/data/:database/registration/:registrationId', { database: 'drzb2013v2' }, {
query: {method:'GET', params:{registraionId:'@id'}, isArray:true}
});
+ }).
+ factory('View', function($resource) {
+ return $resource('/:database/_design/registration/_view/:view?group=true;format=:format', { database: 'drzb2013' }, {
+ key_array: {method:'GET', params:{ format:'key_array' }, isArray:true}
+ });
+
});
</div>
<div class="controls controls-row">
- <input class="my-input span10" ng-model="user.organization" placeholder="<%= $Organization %>" >
+ <input class="my-input span10" ng-model="user.organization" placeholder="<%= $Organization %>" bs-typeahead="organizations" data-items="10" >
</div>
% my $Address = locale en => 'Address', hr => 'Adresa';
hr => 'Organizacija koja uplaćuje R-1 račun' %>
</legend>
-<input class="my-input span10" ng-model="user.r1.organization" ng-required="user.r1.required" placeholder="<%= $Organization %>">
+<input class="my-input span10" ng-model="user.r1.organization" ng-required="user.r1.required" placeholder="<%= $Organization %>" bs-typeahead="organizations" >
<input class="my-input span10" ng-model="user.r1.address" ng-required="user.r1.required" placeholder="<%= $Address %>">
<input class="my-input span5" ng-model="user.r1.OIB" ng-required="user.r1.required" placeholder="OIB">
<div ng-repeat="person in work.persons" class="controls controls-row">
<input class="span2 my-input" ng-model="person.firstname" placeholder="<%= $Name %>" ng-required="has_work" />
<input class="span2 my-input" ng-model="person.surname" placeholder="<%= $Surname %>" ng-required="has_work" />
- <input class="span2 my-input" ng-model="person.organization" placeholder="<%= $Organization %>" >
+ <input class="span2 my-input" ng-model="person.organization" placeholder="<%= $Organization %>" bs-typeahead="organizations" >
<input class="span2 my-input" ng-model="person.email" type="email" placeholder="<%= $Email %>" ng-required="has_work" />
<a class="controls span1 btn btn-danger" href="" ng-click="removePerson(work.persons,person)"><%= locale en => 'delete', hr => 'obriši' %></a>
</div>