<commit_before>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2013 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact <EMAIL>. 
 */

(function() {

    'use strict';

    /**
     * @ngdoc controller
     * @name openlmis-requisition.RequisitionViewController
     * @description
     * Controller for requisition view page
     */

    angular
        .module('openlmis.requisitions')
        .controller('RequisitionSearchController', RequisitionSearchController);

    RequisitionSearchController.$inject = ['$scope', '$state', 'messageService', 'facilityList', 'RequisitionService', 'Status', 'DateUtils'];

    function RequisitionSearchController($scope, $state, messageService, facilityList, RequisitionService, Status, DateUtils) {

        $scope.loadPrograms = loadPrograms;
        $scope.search = search;
        $scope.openRnr = openRnr;

        $scope.facilities = facilityList;
        $scope.statuses = Status.$toList();
        $scope.selectedStatuses = [];

        if (!angular.isArray($scope.facilities) || $scope.facilities.length < 1) {
            $scope.error = messageService.get('msg.facilities.not.found');
        }

        $scope.multiselectSettings = {
            smartButtonMaxItems: 4
        };

        $scope.$watch('selectedFacility.item', function(){
            loadPrograms();
        });

        $scope.gridOptions = { data: 'requisitionList',
            showFooter: false,
            showSelectionCheckbox: false,
            enableColumnResize: true,
            enableColumnMenus: false,
            showFilter: false,
            rowTemplate: 'common/grid/row.html',
            columnDefs: [
                {
                    field: 'program.name', 
                    displayName: messageService.get('program.header')
                }, {
                    field: 'facility.code',
                    displayName: messageService.get('option.value.facility.code')
                }, {
                    field: 'facility.name',
                    displayName: messageService.get('option.value.facility.name')
                }, {
                    field: 'processingPeriod.startDate',
                    displayName: messageService.get('label.period.start.date'),
                    cellFilter: DateUtils.FILTER
                }, {
                    field: 'processingPeriod.endDate',
                    displayName: messageService.get('label.period.end.date'),
                    type: 'date',
                    cellFilter: DateUtils.FILTER
                }, {
                    field: 'createdDate',
                    displayName: messageService.get('label.date.submitted'),
                    type: 'date',
                    cellFilter: DateUtils.FILTER
                },
                {
                    field: 'status',
                    displayName: messageService.get('label.status')
                }, {
                    name: 'emergency',
                    displayName: messageService.get('requisition.type.emergency'),
                    cellTemplate: 'common/grid/emergency-cell.html',
                    width: 110
                }
            ]
        };

        /**
         *
         * @ngdoc function
         * @name openRnr
         * @methodOf openlmis-requisition.RequisitionViewController
         * 
         * @description
         * Redirect to requisition page after clicking on grid row.
         *
         */
        function openRnr(row) {
            $state.go('requisitions.requisition', {
                rnr: row.entity.id
            });
        }

        /**
         *
         * @ngdoc function
         * @name loadPrograms
         * @methodOf openlmis-requisition.RequisitionViewController
         * 
         * @description
         * Loads selected facility supported programs to program select input.
         *
         */
        function loadPrograms() {
            if ($scope.selectedFacility && $scope.selectedFacility.item.supportedPrograms) {
                $scope.programs = $scope.selectedFacility.item.supportedPrograms;
            } else {
                $scope.error = messageService.get('msg.no.program.available');
            }<commit_msg>OLMIS-1220: removed no period for facility error message when there is no facility selected in requisition view<commit_after>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2013 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
 * You should have received a copy of the GNU Affero General Public License along with this program.  If not, see http://www.gnu.org/licenses.  For additional information contact <EMAIL>. 
 */

(function() {

    'use strict';

    /**
     * @ngdoc controller
     * @name openlmis-requisition.RequisitionViewController
     * @description
     * Controller for requisition view page
     */

    angular
        .module('openlmis.requisitions')
        .controller('RequisitionSearchController', RequisitionSearchController);

    RequisitionSearchController.$inject = ['$scope', '$state', 'messageService', 'facilityList', 'RequisitionService', 'Status', 'DateUtils'];

    function RequisitionSearchController($scope, $state, messageService, facilityList, RequisitionService, Status, DateUtils) {

        $scope.loadPrograms = loadPrograms;
        $scope.search = search;
        $scope.openRnr = openRnr;

        $scope.facilities = facilityList;
        $scope.statuses = Status.$toList();
        $scope.selectedStatuses = [];

        if (!angular.isArray($scope.facilities) || $scope.facilities.length < 1) {
            $scope.error = messageService.get('msg.facilities.not.found');
        }

        $scope.multiselectSettings = {
            smartButtonMaxItems: 4
        };

        $scope.$watch('selectedFacility.item', function(){
            loadPrograms();
        });

        $scope.gridOptions = { data: 'requisitionList',
            showFooter: false,
            showSelectionCheckbox: false,
            enableColumnResize: true,
            enableColumnMenus: false,
            showFilter: false,
            rowTemplate: 'common/grid/row.html',
            columnDefs: [
                {
                    field: 'program.name', 
                    displayName: messageService.get('program.header')
                }, {
                    field: 'facility.code',
                    displayName: messageService.get('option.value.facility.code')
                }, {
                    field: 'facility.name',
                    displayName: messageService.get('option.value.facility.name')
                }, {
                    field: 'processingPeriod.startDate',
                    displayName: messageService.get('label.period.start.date'),
                    cellFilter: DateUtils.FILTER
                }, {
                    field: 'processingPeriod.endDate',
                    displayName: messageService.get('label.period.end.date'),
                    type: 'date',
                    cellFilter: DateUtils.FILTER
                }, {
                    field: 'createdDate',
                    displayName: messageService.get('label.date.submitted'),
                    type: 'date',
                    cellFilter: DateUtils.FILTER
                },
                {
                    field: 'status',
                    displayName: messageService.get('label.status')
                }, {
                    name: 'emergency',
                    displayName: messageService.get('requisition.type.emergency'),
                    cellTemplate: 'common/grid/emergency-cell.html',
                    width: 110
                }
            ]
        };

        /**
         *
         * @ngdoc function
         * @name openRnr
         * @methodOf openlmis-requisition.RequisitionViewController
         * 
         * @description
         * Redirect to requisition page after clicking on grid row.
         *
         */
        function openRnr(row) {
            $state.go('requisitions.requisition', {
                rnr: row.entity.id
            });
        }

        /**
         *
         * @ngdoc function
         * @name loadPrograms
         * @methodOf openlmis-requisition.RequisitionViewController
         * 
         * @description
         * Loads selected facility supported programs to program select input.
         *
         */
        function loadPrograms() {
            if (!$scope.selectedFacility) {
                return;
            } else if ($scope.selectedFacility.item.supportedPrograms) {
                $scope.programs = $scope.selectedFacility.item.supportedPrograms;
            } else {
                $scope.error = messageService.get('msg.no.program.available');
            }
{'fraction_non_alphanumeric': 0.09524764387407259, 'fraction_numerical': 0.00240625626629236, 'mean_word_length': 1.8066966797974113, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7254155', 'n_tokens_mistral': 2514, 'n_tokens_neox': 2337, 'n_words': 599}