Skip to content
Snippets Groups Projects
Commit 15958466 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

fix up Reserve pages to work without a 'currentOrg'.

parent 69a70326
No related branches found
No related tags found
No related merge requests found
......@@ -7,30 +7,26 @@ ReserveControllers.controller('VenueList', ['$scope', 'Metabase', 'Reserve',
$scope.orderByField = "name";
$scope.reverseSort = false;
$scope.$watch('currentOrg', function(org){
if(!org) return;
Reserve.queryInfo(org.id).then(function(queryInfo){
$scope.search = function(){
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.venue_table,
'aggregation': ['rows'],
'breakout': [null],
'filter': [null, null],
'limit': null
}
}, function(queryResponse){
$scope.venues = Reserve.convertToObjects(queryResponse.data);
}, function(error){
console.log(error);
});
};
Reserve.queryInfo().then(function(queryInfo){
$scope.search = function(){
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.venue_table,
'aggregation': ['rows'],
'breakout': [null],
'filter': [null, null],
'limit': null
}
}, function(queryResponse){
$scope.venues = Reserve.convertToObjects(queryResponse.data);
}, function(error){
console.log(error);
});
};
$scope.search();
});
$scope.search();
});
}
]);
......@@ -40,62 +36,59 @@ ReserveControllers.controller('VenueDetail', ['$scope', '$routeParams', 'Metabas
$scope.orderByField = "user";
$scope.reverseSort = false;
$scope.$watch('currentOrg', function(org){
if(!org) return;
Reserve.queryInfo(org.id).then(function(queryInfo){
Metabase.dataset({
Reserve.queryInfo().then(function(queryInfo){
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.venue_table,
'aggregation': ['rows'],
'breakout': [null],
'filter': ['=', queryInfo.venue_id_field, $routeParams.venueId]
}
}, function(venueResponse){
$scope.venue = Reserve.convertToObjects(venueResponse.data)[0];
var dataset_query = {
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.venue_table,
'fields':[
queryInfo.user_firstName_field,
queryInfo.user_lastName_field,
queryInfo.user_id_field,
queryInfo.booking_guests_field,
queryInfo.booking_overage_field,
queryInfo.booking_rating_field,
queryInfo.booking_createdAt_field,
queryInfo.booking_updatedAt_field
],
'from':[{
'table': queryInfo.user_table
}, {
'table': queryInfo.booking_table,
'join_type': 'inner',
'conditions':[
{
'src_field': queryInfo.user_id_field,
'dest_field': queryInfo.booking_user_fk
}
]
}],
'aggregation': ['rows'],
'breakout': [null],
'filter': ['=', queryInfo.venue_id_field, $routeParams.venueId]
'filter': ['=', queryInfo.booking_venue_fk, $routeParams.venueId]
}
}, function(venueResponse){
$scope.venue = Reserve.convertToObjects(venueResponse.data)[0];
var dataset_query = {
'database': queryInfo.database,
'type': 'query',
'query': {
'fields':[
queryInfo.user_firstName_field,
queryInfo.user_lastName_field,
queryInfo.user_id_field,
queryInfo.booking_guests_field,
queryInfo.booking_overage_field,
queryInfo.booking_rating_field,
queryInfo.booking_createdAt_field,
queryInfo.booking_updatedAt_field
],
'from':[{
'table': queryInfo.user_table
}, {
'table': queryInfo.booking_table,
'join_type': 'inner',
'conditions':[
{
'src_field': queryInfo.user_id_field,
'dest_field': queryInfo.booking_user_fk
}
]
}],
'aggregation': ['rows'],
'breakout': [null],
'filter': ['=', queryInfo.booking_venue_fk, $routeParams.venueId]
}
};
Metabase.dataset(dataset_query,
function(bookingsResponse){
$scope.bookings = Reserve.convertToObjects(bookingsResponse.data);
}, function(error){
console.log(error);
});
};
Metabase.dataset(dataset_query,
function(bookingsResponse){
$scope.bookings = Reserve.convertToObjects(bookingsResponse.data);
}, function(error){
console.log(error);
});
}, function(error){
console.log(error);
});
});
}
......@@ -107,30 +100,26 @@ ReserveControllers.controller('UserList', ['$scope', 'Metabase', 'Reserve',
$scope.orderByField = "firstName";
$scope.reverseSort = false;
$scope.$watch('currentOrg', function(org){
if(!org) return;
Reserve.queryInfo(org.id).then(function(queryInfo){
$scope.search = function(){
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.user_table,
'aggregation': ['rows'],
'breakout': [null],
'filter': [null, null],
'limit': null
}
}, function(queryResponse){
$scope.users = Reserve.convertToObjects(queryResponse.data);
}, function(error){
console.log(error);
});
};
Reserve.queryInfo().then(function(queryInfo){
$scope.search = function(){
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.user_table,
'aggregation': ['rows'],
'breakout': [null],
'filter': [null, null],
'limit': null
}
}, function(queryResponse){
$scope.users = Reserve.convertToObjects(queryResponse.data);
}, function(error){
console.log(error);
});
};
$scope.search();
});
$scope.search();
});
}
......@@ -142,59 +131,56 @@ ReserveControllers.controller('UserDetail', ['$scope', '$routeParams', 'Metabase
$scope.orderByField = "user";
$scope.reverseSort = false;
$scope.$watch('currentOrg', function(org){
if(!org) return;
Reserve.queryInfo(org.id).then(function(queryInfo){
Reserve.queryInfo().then(function(queryInfo){
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.user_table,
'aggregation': ['rows'],
'breakout': [null],
'filter': ['=', queryInfo.user_id_field, $routeParams.userId]
}
}, function(userResponse){
$scope.user = Reserve.convertToObjects(userResponse.data)[0];
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'source_table': queryInfo.user_table,
'fields':[
queryInfo.venue_name_field,
queryInfo.venue_id_field,
queryInfo.booking_guests_field,
queryInfo.booking_overage_field,
queryInfo.booking_rating_field,
queryInfo.booking_createdAt_field,
queryInfo.booking_updatedAt_field
],
'from':[{
'table': queryInfo.venue_table
}, {
'table': queryInfo.booking_table,
'join_type': 'inner',
'conditions':[
{
'src_field': queryInfo.venue_id_field,
'dest_field': queryInfo.booking_venue_fk
}
]
}],
'aggregation': ['rows'],
'breakout': [null],
'filter': ['=', queryInfo.user_id_field, $routeParams.userId]
'filter': ['=', queryInfo.booking_user_fk, $routeParams.userId]
}
}, function(userResponse){
$scope.user = Reserve.convertToObjects(userResponse.data)[0];
Metabase.dataset({
'database': queryInfo.database,
'type': 'query',
'query': {
'fields':[
queryInfo.venue_name_field,
queryInfo.venue_id_field,
queryInfo.booking_guests_field,
queryInfo.booking_overage_field,
queryInfo.booking_rating_field,
queryInfo.booking_createdAt_field,
queryInfo.booking_updatedAt_field
],
'from':[{
'table': queryInfo.venue_table
}, {
'table': queryInfo.booking_table,
'join_type': 'inner',
'conditions':[
{
'src_field': queryInfo.venue_id_field,
'dest_field': queryInfo.booking_venue_fk
}
]
}],
'aggregation': ['rows'],
'breakout': [null],
'filter': ['=', queryInfo.booking_user_fk, $routeParams.userId]
}
}, function(bookingsResponse){
$scope.bookings = Reserve.convertToObjects(bookingsResponse.data);
}, function(error){
console.log(error);
});
}, function(bookingsResponse){
$scope.bookings = Reserve.convertToObjects(bookingsResponse.data);
}, function(error){
console.log(error);
});
}, function(error){
console.log(error);
});
});
}
......
......@@ -12,9 +12,9 @@ var Reserve = angular.module('corvus.reserve', [
]);
Reserve.config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/:orgSlug/venue/', {templateUrl: '/app/reserve/partials/venue_list.html', controller: 'VenueList'});
$routeProvider.when('/:orgSlug/venue/:venueId', {templateUrl: '/app/reserve/partials/venue_detail.html', controller: 'VenueDetail'});
$routeProvider.when('/reserve/venue/', {templateUrl: '/app/reserve/partials/venue_list.html', controller: 'VenueList'});
$routeProvider.when('/reserve/venue/:venueId', {templateUrl: '/app/reserve/partials/venue_detail.html', controller: 'VenueDetail'});
$routeProvider.when('/:orgSlug/user/', {templateUrl: '/app/reserve/partials/user_list.html', controller: 'UserList'});
$routeProvider.when('/:orgSlug/user/:userId', {templateUrl: '/app/reserve/partials/user_detail.html', controller: 'UserDetail'});
$routeProvider.when('/reserve/user/', {templateUrl: '/app/reserve/partials/user_list.html', controller: 'UserList'});
$routeProvider.when('/reserve/user/:userId', {templateUrl: '/app/reserve/partials/user_detail.html', controller: 'UserDetail'});
}]);
......@@ -30,12 +30,10 @@ ReserveServices.service('Reserve', ['$resource', '$q', 'Metabase',
var USER_FIRST_NAME_FIELD_NAME = "firstName";
var USER_LAST_NAME_FIELD_NAME = "lastName";
this.queryInfo = function(orgId){
this.queryInfo = function() {
var deferred = $q.defer();
var queryInfo = {};
Metabase.db_list({
'orgId': orgId
}, function(dbs){
Metabase.db_list(function(dbs){
dbs.forEach(function(db){
if(db.name == RESERVE_DB_NAME){
queryInfo.database = db.id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment