Add the survey list

pull/339/head
Ayyoub allali 2017-08-21 08:12:49 +01:00
parent 4f60ae1ca4
commit c025a75de3
5 changed files with 89 additions and 15 deletions

View File

@ -5,7 +5,33 @@
.controller('list', list);
/** @ngInject */
function list(SurveyService, $scope) {
function list( SurveyService, $scope, $log, $state) {
var vm = this;
function loadSurveys() {
SurveyService
.list()
.then(function (data){
vm.surveys = data;
$log.info("Got the survey data",data);
}, function (error){
$log.error(error);
});
}
function goToCreate() {
$log.info("Go to create");
$state.go('surveys.create');
}
function activate(){
vm.surveys = [];
vm.goToCreate = goToCreate;
loadSurveys();
}
activate();
}

View File

@ -1,11 +1,47 @@
<div id="surveys" class="widgets">
<div class="row">
<div class="col-md-12">
<div ba-panel ba-panel-title="list" ba-panel-class="with-scroll">
</div>
</div>
<div ba-panel ba-panel-title="My surveys" ba-panel-class="with-scroll">
<div ng-if="vm.surveys.length <= 0">
<button ng-click="vm.goToCreate()" class="btn btn-success btn-lg">
New survey
</button>
</div>
<table ng-if="vm.surveys.length > 0" class="table table-bordered table-hover">
<thead>
<tr class="black-muted-bg" >
<th></td>
<th>Title</td>
<th>Last edit</td>
<th>Responses</td>
<th>Actions</td>
</tr>
<thead>
<tbody>
<tr ng-repeat="survey in vm.surveys track by survey.id" >
<td>
{{ $index }}
</td>
<td>
{{ survey.name }} <br />
Create at : {{ survey.createdAt | date:'shortDate' }}
</td>
<td>
{{ survey.updatedAt | date:'shortDate' }}
</td>
<td> {{ survey.responses || 0 }}
<td>
Action ...
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
List surveys
<div>

View File

@ -1,6 +1,7 @@
(function () {
'use strict';
angular.module('BlurAdmin.pages.surveys.list',['BlurAdmin.pages.surveys']);
angular.module('BlurAdmin.pages.surveys.list',
['BlurAdmin.pages.surveys']);
})();

View File

@ -10,16 +10,27 @@
/** @ngInject */
function SurveyService($http, $q) {
var apiBaseUrl = "http://localhost:9000"
var endpoint = apiBaseUrl + "/surveys";
function list() {
return [];
function list(params) {
params = params || {};
var deferred = $q.defer();
$http.get(endpoint)
.success(function(data) {
deferred.resolve(data);
}).error(function(msg, code) {
deferred.reject(msg);
});
return deferred.promise;
return $http.get(endpoint, params);
}
function create(survey) {
var url = apiBaseUrl + "/surveys";
// Make the API call
return $http.post(url, survey);
return $http.post(endpoint, survey);
}
function edit(survery) {

View File

@ -33,8 +33,8 @@
}).state('surveys.list', {
url: '/list',
templateUrl: 'app/pages/surveys/list/list.html',
controller: "list",
title: 'list all models',
controller: "list as vm",
title: 'My surveys',
sidebarMeta: {
order: 2000,
},