all files / app/main/components/material-docs/ material-doc-template.controller.js

16.67% Statements 5/30
0% Branches 0/14
10% Functions 1/10
16.67% Lines 5/30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85                                                                                                                                                                
(function ()
{
    'use strict';
 
    angular
        .module('app.components.material-docs')
        .constant('ANGULAR_MATERIAL_VERSION', '1.1.0')
        .controller('DocTemplateController', DocTemplateController);
 
    /** @ngInject */
    function DocTemplateController(DEMOS, COMPONENTS, $state, $http, $templateCache, ANGULAR_MATERIAL_VERSION)
    {
        var vm = this;
        var component = $state.current.data;
        vm.materialVersion = ANGULAR_MATERIAL_VERSION;
 
        vm.componentName = component.name;
 
        vm.component = getComponent(component.moduleName);
 
        if ( !component.excludeDemo )
        {
            vm.demo = getDemo(component.moduleName);
        }
 
        if ( vm.component )
        {
            vm.docs = vm.component.docs;
        }
 
        if ( vm.demo )
        {
            vm.demos = [];
 
            angular.forEach(vm.demo.demos, function (demo)
            {
                // Get displayed contents (un-minified)
                var files = [demo.index]
                    .concat(demo.js || [])
                    .concat(demo.css || [])
                    .concat(demo.html || []);
                files.forEach(function (file)
                {
                    file.httpPromise = $http.get('app/main/components/material-docs/' + file.outputPath, {cache: $templateCache})
                        .then(function (response)
                        {
                            file.contents = response.data
                                .replace('<head/>', '');
                            return file.contents;
                        });
                });
                demo.$files = files;
                vm.demos.push(demo);
            });
 
            vm.demos = vm.demos.sort(function (a, b)
            {
                return a.name > b.name ? 1 : -1;
            });
        }
 
        // Data
 
        // Methods
 
        //////////
 
        function getDemo(value)
        {
            return DEMOS.filter(function (x)
            {
                return x.moduleName === value;
            })[0];
        }
 
        function getComponent(value)
        {
            return COMPONENTS.filter(function (x)
            {
                return x.name === value;
            })[0];
        }
    }
 
})();