<commit_before>'use strict';

var module = angular.module('MarkLogicRESTClientApp',
    ['ngResource', 'ngRoute', 'toastr', 'ui.bootstrap']
);

module.config(function($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: '/views/list.html',
            controller: 'ProductListController'
        })
        .when('/search', {
            templateUrl: '/views/search.html',
            controller: 'ApplicationController'
        })
        .when('/products/new', {
            templateUrl: '/views/create.html',
            controller: 'ProductCreateController'
        })
        .when('/products/:sku', {
            templateUrl: '/views/detail.html',
            controller: 'ProductDetailController'
        })
        .otherwise({
            redirectTo: '/'
        });
});

module.factory('MarkLogicService', function ($resource) {
    var service = $resource('/products/:sku.json', {id: '@sku'}, {
        getProduct:    {method: 'GET'},
        getProducts:   {method: 'GET',  url: '/products.json', isArray: true},
        addProduct:    {method: 'POST', url: '/products' },
        removeProduct: {method: 'DELETE'}
    });
    service.prototype.isNew = function() {
        return (typeof(this.id) === 'undefined');
    };
    return service;
});

/* ======================================================================= */

module.controller('ProductListController', function($scope, $modal, $log, MarkLogicService) {
    $scope.products = MarkLogicService.getProducts();
    $scope.totalItems = 40;
    $scope.currentPage = 1;

    $scope.confirmDeletion = function (product) {
        var modalInstance = $modal.open({
            templateUrl: 'confirmDeletionModal.html',
            controller: ModalInstanceCtrl,
            size: 'sm',
            resolve: {
                product: function () {
                    return product;
                }
            }
        });
        // As soon the user made a decision
        modalInstance.result.then(function(product) {
            $log.info('Will now delete product: ' + product.sku);
            MarkLogicService.removeProduct({sku: product.sku});
            // (in case paging is not an issue, delete directly)
            //  var index = $scope.products.indexOf(product);
            //  $scope.products.splice(index, 1);<commit_msg>Added toast on successful deletion of product.<commit_after>'use strict';

var module = angular.module('MarkLogicRESTClientApp',
    ['ngResource', 'ngRoute', 'toastr', 'ui.bootstrap']
);

module.config(function($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: '/views/list.html',
            controller: 'ProductListController'
        })
        .when('/search', {
            templateUrl: '/views/search.html',
            controller: 'ApplicationController'
        })
        .when('/products/new', {
            templateUrl: '/views/create.html',
            controller: 'ProductCreateController'
        })
        .when('/products/:sku', {
            templateUrl: '/views/detail.html',
            controller: 'ProductDetailController'
        })
        .otherwise({
            redirectTo: '/'
        });
});

module.factory('MarkLogicService', function ($resource) {
    var service = $resource('/products/:sku.json', {id: '@sku'}, {
        getProduct:    {method: 'GET'},
        getProducts:   {method: 'GET',  url: '/products.json', isArray: true},
        addProduct:    {method: 'POST', url: '/products' },
        removeProduct: {method: 'DELETE'}
    });
    service.prototype.isNew = function() {
        return (typeof(this.id) === 'undefined');
    };
    return service;
});

/* ======================================================================= */

module.controller('ProductListController', function($scope, $modal, $log, MarkLogicService, toastr) {
    $scope.products = MarkLogicService.getProducts();
    $scope.totalItems = 40;  // FIXME
    $scope.currentPage = 1;  // FIXME

    $scope.confirmDeletion = function (product) {
        var modalInstance = $modal.open({
            templateUrl: 'confirmDeletionModal.html',
            controller: ModalInstanceCtrl,
            size: 'sm',
            resolve: {
                product: function () {
                    return product;
                }
            }
        });
        // As soon the user made a decision
        modalInstance.result.then(function(product) {
            $log.info('Will now delete product: ' + product.sku);
            MarkLogicService.removeProduct({sku: product.sku});
            toastr.success("Deleted product '" + product.name + "'");
            // (in case paging is not an issue, delete directly)
            //  var index = $scope.products.indexOf(product);
            //  $scope.products.splice(index, 1);
{'fraction_non_alphanumeric': 0.1727857291018461, 'fraction_numerical': 0.0016594067620825555, 'mean_word_length': 2.2232620320855614, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5882372', 'n_tokens_mistral': 1298, 'n_tokens_neox': 1268, 'n_words': 257}