Skip to content

Commit

Permalink
Merge 'develop' for v1.1.16 release
Browse files Browse the repository at this point in the history
  • Loading branch information
vastbinderj committed Apr 21, 2016
2 parents 4a5d63c + e5bb2d7 commit fa3a65d
Show file tree
Hide file tree
Showing 45 changed files with 1,152 additions and 695 deletions.
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Dashboard",
"version": "1.1.141",
"version": "1.1.16",
"description": "Ottemo Administration Tool",
"main": "gulpfile.js",
"repository": {
Expand All @@ -21,10 +21,7 @@
"gulp-imagemin": "^2.0.0",
"gulp-inline-css": "^3.0.1",
"gulp-jshint": "^1.10.0",
"gulp-livereload": "^3.8.0",
"gulp-load-plugins": "^1.2.0",
"gulp-minify-css": "^0.3.13",
"gulp-minify-html": "^0.1.8",
"gulp-plumber": "^1.0.1",
"gulp-rename": "^1.2.2",
"gulp-replace-task": "^0.11.0",
Expand Down
1 change: 1 addition & 0 deletions src/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@import 'login/login';
@import 'order/order';
@import 'product/product';
@import 'reports/reports';
@import 'seo/seo';
@import 'subscriptions/subscriptions';
@import 'visitor/visitor';
7 changes: 5 additions & 2 deletions src/app/category/api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ angular.module("categoryModule")
"addProduct": {
method: "POST",
params: {
categoryID: "@categoryId",
productID: "@productId"
// this is a post method, but we don't really care about the data as much
// as the params, the `@` extracts the param values from the post data
// so that we don't have to write `addProduct({},params)
categoryID: "@categoryID",
productID: "@productID"
},
url: REST_SERVER_URI + "/category/:categoryID/product/:productID"
},
Expand Down
161 changes: 81 additions & 80 deletions src/app/category/edit.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ angular.module("categoryModule")
"dashboardUtilsService",
"_",
function ($scope, $routeParams, $location, $q, categoryApiService, dashboardUtilsService, _) {
var categoryId, rememberProducts, oldProducts, getDefaultCategory;

var savedProducts = []

// Initialize SEO
if (typeof $scope.initSeo === "function") {
$scope.initSeo("category");
}

categoryId = $routeParams.id;
var categoryId = $routeParams.id;

if (!categoryId && categoryId !== "new") {
$location.path("/categories");
Expand All @@ -25,21 +27,14 @@ function ($scope, $routeParams, $location, $q, categoryApiService, dashboardUtil
categoryId = null;
}

oldProducts = [];

getDefaultCategory = function () {
function getDefaultCategory() {
return {
name: "",
"parent_id": "",
"products": []
};
};

/**
* Current selected category
*
* @type {Object}
*/
$scope.category = {};

/**
Expand All @@ -55,7 +50,7 @@ function ($scope, $routeParams, $location, $q, categoryApiService, dashboardUtil
var result = response.result || {};
$scope.category = result;
$scope.category.parent = $scope.category['parent_id'];
$scope.category.products = $scope.category.product_ids;
savedProducts = $scope.category.product_ids;
});
}

Expand All @@ -64,34 +59,34 @@ function ($scope, $routeParams, $location, $q, categoryApiService, dashboardUtil
};

$scope.saveProducts = function () {
var promises = [];

var categoryId = $scope.category.id || $scope.category._id;
var _prev = $scope.category.product_ids;
var _new = $scope.category.products;

var products_to_remove = _.difference(_prev,_new);
var products_to_add = _.difference(_new,_prev);

if (products_to_remove.length){
_.each(products_to_remove, function(productID){
promises.push(categoryApiService.removeProduct({
categoryID: categoryId,
productID: productID
}))
})
}
var categoryID = $scope.category.id || $scope.category._id;
var newProductList = $scope.category.product_ids;

if (products_to_add.length){
_.each(products_to_add, function(productID){
promises.push(categoryApiService.addProduct({
categoryId: categoryId,
productId: productID
}))
})
}
var toRemove = _.difference(savedProducts, newProductList);
var toAdd = _.difference(newProductList, savedProducts);

var promises = _.map(toRemove, removePid);
promises = promises.concat( _.map(toAdd, addPid) );

return $q.all(promises);

/////////////////

function removePid(productID){
var params = {
categoryID: categoryID,
productID: productID,
};
return categoryApiService.removeProduct(params).$promise;
}

function addPid(productID){
var params = {
categoryID: categoryID,
productID: productID,
};
return categoryApiService.addProduct(params).$promise;
}
};

/**
Expand All @@ -101,75 +96,81 @@ function ($scope, $routeParams, $location, $q, categoryApiService, dashboardUtil
$scope.save = function () {
$('[ng-click="save()"]').addClass('disabled').append('<i class="fa fa-spin fa-spinner"><i>').siblings('.btn').addClass('disabled');

var id, defer, saveSuccess, saveError, updateSuccess, updateError;
defer = $q.defer();
var defer = $q.defer();
var id = $scope.category.id || $scope.category._id;

// Props that aren't recognized by the server
delete $scope.category.parent;
delete $scope.category.path;
delete $scope.category.products;

if (!id) {
if ($scope.category.name !== '') {

// Props that aren't recognized by the server
delete $scope.category.product_ids;

categoryApiService.save($scope.category).$promise
.then(saveSuccess, saveError)
.then(function(){
savedProducts = $scope.category.product_ids;
});
}
} else {
$scope.category.id = id;
$scope.saveProducts().then(function () {

// Props that aren't recognized by the server
delete $scope.category.product_ids;

if (typeof $scope.category !== "undefined") {
id = $scope.category.id || $scope.category._id;
categoryApiService.update($scope.category).$promise
.then(updateSuccess, updateError)
.then(function(){
savedProducts = $scope.category.product_ids;
});
});
}

saveSuccess = function (response) {
return defer.promise;

////////////////

function saveSuccess(response) {
if (response.error === null) {
$scope.category = response.result || getDefaultCategory();
$scope.message = dashboardUtilsService.getMessage(null, 'success', 'Category was created successfully');
defer.resolve(true);
}
$('[ng-click="save()"]').removeClass('disabled').children('i').remove();
$('[ng-click="save()"]').siblings('.btn').removeClass('disabled');

allowSaving();
};

saveError = function () {
function saveError() {
defer.resolve(false);
$('[ng-click="save()"]').removeClass('disabled').children('i').remove();
$('[ng-click="save()"]').siblings('.btn').removeClass('disabled');
allowSaving();
};

updateSuccess = function (response) {
function updateSuccess(response) {
if (response.error === null) {
$scope.category = response.result || getDefaultCategory();
$scope.message = dashboardUtilsService.getMessage(null, 'success', 'Product was updated successfully');
defer.resolve(true);
$('[ng-click="save()"]').removeClass('disabled').children('i').remove();
$('[ng-click="save()"]').siblings('.btn').removeClass('disabled');

allowSaving();
}
};

updateError = function () {
function updateError() {
defer.resolve(false);
$('[ng-click="save()"]').removeClass('disabled').children('i').remove();
$('[ng-click="save()"]').siblings('.btn').removeClass('disabled');
allowSaving();
};

delete $scope.category.parent;
delete $scope.category.path;


if (!id) {
if ($scope.category.name !== '') {

delete $scope.category.products;
categoryApiService.save($scope.category).$promise
.then(saveSuccess, saveError)
.then(function(){
$scope.category.products = $scope.category.product_ids;
});
}
} else {
$scope.category.id = id;
$scope.saveProducts().then(function () {

// Clean the associated product list off, before posting up
delete $scope.category.products;
categoryApiService.update($scope.category).$promise
.then(updateSuccess, updateError)
.then(function(){
$scope.category.products = $scope.category.product_ids;
});
});

// Refactor
function allowSaving() {
$('[ng-click="save()"]').removeClass('disabled').children('i').remove();
$('[ng-click="save()"]').siblings('.btn').removeClass('disabled');
}

return defer.promise;
};

}]);
40 changes: 40 additions & 0 deletions src/app/config/directives/ot-store-date.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
angular.module("configModule")

.directive('otStoreDate',
['timezoneService', '$filter',
function(timezoneService, $filter) {
return {
restrict: 'EA',
template: '{{localDate}}',
scope: {
'date' : '=',
},
link: function(scope, element, attrs) {

scope.localDate = '';

activate();

////////////////

function activate() {
update();
scope.$watch('date', update);
}

function update() {
scope.localDate = scope.date ? 'Loading...' : '-';

if (!scope.date) {
return;
}

timezoneService.get().then(function(tz){
scope.localDate = $filter('date')(scope.date, 'MM/dd/yyyy hh:mma', tz);
});
}
}
};
}
]);

12 changes: 0 additions & 12 deletions src/app/config/filters/ot-storedate.js

This file was deleted.

22 changes: 10 additions & 12 deletions src/app/config/init.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/**
* Config Module
*/
angular.module("configModule", ["ngRoute", "ngResource", "coreModule"])
angular.module('configModule', [
'ngRoute',
'ngResource',
'coreModule'
])

.config(["$routeProvider", function ($routeProvider) {
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when("/settings/:group", {
templateUrl: "/views/config/edit.html",
controller: "configEditController"
.when('/settings/:group', {
templateUrl: '/views/config/edit.html',
controller: 'configEditController',
});
}])
}]);

.run(['timezoneService', function (timezoneService) {
timezoneService.init();
}]);
Loading

0 comments on commit fa3a65d

Please sign in to comment.