@@ -43,11 +43,20 @@ angular.module('patternfly', [
43
43
'patternfly.form' ,
44
44
'patternfly.notification' ,
45
45
'patternfly.select' ,
46
+ 'patternfly.sort' ,
46
47
'patternfly.utils' ,
47
48
'patternfly.validation' ,
48
49
'patternfly.views'
49
50
] ) ;
50
51
52
+ ; /**
53
+ * @name patternfly card
54
+ *
55
+ * @description
56
+ * Sort module for patternfly.
57
+ *
58
+ */
59
+ angular . module ( 'patternfly.sort' , [ ] ) ;
51
60
;
52
61
angular . module ( 'patternfly.utils' , [ ] ) ;
53
62
; /**
@@ -2469,6 +2478,233 @@ angular.module('patternfly.select', []).directive('pfSelect', ["$timeout", funct
2469
2478
}
2470
2479
} ;
2471
2480
} ] ) ;
2481
+ ; /**
2482
+ * @ngdoc directive
2483
+ * @name patternfly.sort.directive:pfSimpleSort
2484
+ *
2485
+ * @description
2486
+ * Directive for a simple sort component
2487
+ * <br><br>
2488
+ *
2489
+ * @param {object } config configuration settings for the sort:<br/>
2490
+ * <ul style='list-style-type: none'>
2491
+ * <li>.fields - (Array) List of sortable fields containing:
2492
+ * <ul style='list-style-type: none'>
2493
+ * <li>.id - (String) Unique Id for the sort field
2494
+ * <li>.title - (String) The title to display for the sort field
2495
+ * <li>.sortType - (String) The sort type, 'alpha' or 'numeric'
2496
+ * </ul>
2497
+ * <li>.sortId - (Object) Id of the current sort field
2498
+ * <li>.isAscending - (boolean) Current sort direction is ascending. True for ascending, False for descending
2499
+ * <li>.onSortChange - ( function(sortId, sortDirection ) Function to call when the current sort params change
2500
+ * </ul>
2501
+ *
2502
+ * @example
2503
+ <example module="patternfly.sort">
2504
+ <file name="index.html">
2505
+ <div ng-controller="ViewCtrl" class="row example-container">
2506
+ <div class="col-md-12">
2507
+ <div pf-simple-sort id="exampleSimpleSort" config="sortConfig"></div>
2508
+ </div>
2509
+ <hr class="col-md-12">
2510
+ <div class="col-md-12">
2511
+ <label class="events-label">Items: </label>
2512
+ </div>
2513
+ <div class="col-md-12">
2514
+ <div ng-repeat="item in items" class="col-md-12 cfme-row-column">
2515
+ <div class="row">
2516
+ <div class="col-md-3">
2517
+ <span>{{item.name}}</span>
2518
+ </div>
2519
+ <div class="col-md-3">
2520
+ <span>{{item.count}}</span>
2521
+ </div>
2522
+ <div class="col-md-3">
2523
+ <span>{{item.description}}</span>
2524
+ </div>
2525
+ </div>
2526
+ </div>
2527
+ </div>
2528
+ </div>
2529
+ </file>
2530
+
2531
+ <file name="script.js">
2532
+ angular.module('patternfly.sort').controller('ViewCtrl', ['$scope',
2533
+ function ($scope) {
2534
+ $scope.items = [
2535
+ {
2536
+ name: "Item 7",
2537
+ count: 432,
2538
+ description: 'Very nice item'
2539
+ },
2540
+ {
2541
+ name: "Item 6",
2542
+ count: 22,
2543
+ description: 'It lasts forever'
2544
+ },
2545
+ {
2546
+ name: "Item 3",
2547
+ count: 632,
2548
+ description: 'Good stuff cheap'
2549
+ },
2550
+ {
2551
+ name: "Item 2",
2552
+ count: 12,
2553
+ description: 'Fantastic'
2554
+ },
2555
+ {
2556
+ name: "Item 9",
2557
+ count: 99,
2558
+ description: 'It does alright'
2559
+ },
2560
+ {
2561
+ name: "Item 4",
2562
+ count: 442,
2563
+ description: 'Horrible'
2564
+ },
2565
+ {
2566
+ name: "Item 1",
2567
+ count: 42,
2568
+ description: 'Most excellent'
2569
+ },
2570
+ {
2571
+ name: "Item 8",
2572
+ count: 2,
2573
+ description: 'Get it while it lasts'
2574
+ },
2575
+ {
2576
+ name: "Item 5",
2577
+ count: 321,
2578
+ description: 'Beautiful style'
2579
+ }
2580
+ ];
2581
+
2582
+ var compareFn = function(item1, item2) {
2583
+ var compValue = 0;
2584
+ if ($scope.sortConfig.currentField.id === 'name') {
2585
+ compValue = item1.name.localeCompare(item2.name);
2586
+ } else if ($scope.sortConfig.currentField.id === 'count') {
2587
+ compValue = item1.count - item2.count;
2588
+ } else if ($scope.sortConfig.currentField.id === 'description') {
2589
+ compValue = item1.description.localeCompare(item2.description);
2590
+ }
2591
+
2592
+ if (!$scope.sortConfig.isAscending) {
2593
+ compValue = compValue * -1;
2594
+ }
2595
+
2596
+ return compValue;
2597
+ };
2598
+
2599
+ var sortChange = function (sortId, isAscending) {
2600
+ $scope.items.sort(compareFn);
2601
+ };
2602
+
2603
+ $scope.sortConfig = {
2604
+ fields: [
2605
+ {
2606
+ id: 'name',
2607
+ title: 'Name',
2608
+ sortType: 'alpha'
2609
+ },
2610
+ {
2611
+ id: 'count',
2612
+ title: 'Count',
2613
+ sortType: 'numeric'
2614
+ },
2615
+ {
2616
+ id: 'description',
2617
+ title: 'Description',
2618
+ sortType: 'alpha'
2619
+ }
2620
+ ],
2621
+ onSortChange: sortChange
2622
+ };
2623
+ }
2624
+ ]);
2625
+ </file>
2626
+ </example>
2627
+ */
2628
+ angular . module ( 'patternfly.sort' ) . directive ( 'pfSimpleSort' ,
2629
+ function ( ) {
2630
+ 'use strict' ;
2631
+ return {
2632
+ restrict : 'A' ,
2633
+ scope : {
2634
+ config : '='
2635
+ } ,
2636
+ templateUrl : 'sort/simple-sort.html' ,
2637
+ controller : [ "$scope" , function ( $scope ) {
2638
+ $scope . setupConfig = function ( ) {
2639
+ var updated = false ;
2640
+
2641
+ if ( $scope . config . fields === undefined ) {
2642
+ $scope . config . fields = [ ] ;
2643
+ }
2644
+
2645
+ if ( $scope . config . fields . length > 0 ) {
2646
+ if ( $scope . config . currentField === undefined ) {
2647
+ $scope . config . currentField = $scope . config . fields [ 0 ] ;
2648
+ updated = true ;
2649
+ }
2650
+ if ( $scope . config . isAscending === undefined ) {
2651
+ $scope . config . isAscending = true ;
2652
+ updated = true ;
2653
+ }
2654
+ }
2655
+
2656
+ if ( updated === true && $scope . config . onSortChange ) {
2657
+ $scope . config . onSortChange ( $scope . config . currentField , $scope . config . isAscending ) ;
2658
+ }
2659
+ } ;
2660
+
2661
+ $scope . selectField = function ( field ) {
2662
+ $scope . config . currentField = field ;
2663
+
2664
+ if ( $scope . config . onSortChange ) {
2665
+ $scope . config . onSortChange ( $scope . config . currentField , $scope . config . isAscending ) ;
2666
+ }
2667
+ } ;
2668
+
2669
+ $scope . changeDirection = function ( ) {
2670
+ $scope . config . isAscending = ! $scope . config . isAscending ;
2671
+
2672
+ if ( $scope . config . onSortChange ) {
2673
+ $scope . config . onSortChange ( $scope . config . currentField , $scope . config . currentDirection ) ;
2674
+ }
2675
+ } ;
2676
+
2677
+ $scope . getSortIconClass = function ( ) {
2678
+ var iconClass ;
2679
+
2680
+ if ( $scope . config . currentField . sortType === 'numeric' ) {
2681
+ if ( $scope . config . isAscending ) {
2682
+ iconClass = 'fa fa-sort-numeric-asc' ;
2683
+ } else {
2684
+ iconClass = 'fa fa-sort-numeric-desc' ;
2685
+ }
2686
+ } else {
2687
+ if ( $scope . config . isAscending ) {
2688
+ iconClass = 'fa fa-sort-alpha-asc' ;
2689
+ } else {
2690
+ iconClass = 'fa fa-sort-alpha-desc' ;
2691
+ }
2692
+ }
2693
+
2694
+ return iconClass ;
2695
+ } ;
2696
+
2697
+ $scope . setupConfig ( ) ;
2698
+ } ] ,
2699
+
2700
+ link : function ( scope , element , attrs ) {
2701
+ scope . $watch ( 'config' , function ( ) {
2702
+ scope . setupConfig ( ) ;
2703
+ } , true ) ;
2704
+ }
2705
+ } ;
2706
+ }
2707
+ ) ;
2472
2708
;
2473
2709
/**
2474
2710
* @ngdoc directive
@@ -3793,6 +4029,14 @@ angular.module('patternfly.views').directive('pfDataToolbar',
3793
4029
"<div class=\"alert alert-{{pfNotificationType}}\"><button ng-show=pfNotificationPersistent type=button class=close ng-click=$parent.notifications.remove($index)><span aria-hidden=true>×</span><span class=sr-only>Close</span></button> <span class=\"pficon pficon-ok\" ng-show=\"pfNotificationType === 'success'\"></span> <span class=\"pficon pficon-info\" ng-show=\"pfNotificationType === 'info'\"></span> <span class=\"pficon pficon-error-circle-o\" ng-show=\"pfNotificationType === 'danger'\"></span> <span class=\"pficon pficon-warning-triangle-o\" ng-show=\"pfNotificationType === 'warning'\"></span> <strong>{{pfNotificationHeader}}</strong> {{pfNotificationMessage}}</div>"
3794
4030
) ;
3795
4031
4032
+ } ] ) ;
4033
+ ; angular . module ( 'patternfly.sort' ) . run ( [ '$templateCache' , function ( $templateCache ) {
4034
+ 'use strict' ;
4035
+
4036
+ $templateCache . put ( 'sort/simple-sort.html' ,
4037
+ "<div class=simple-sort><form><div class=form-group><div class=input-group><div dropdown class=input-group-btn><button dropdown-toggle type=button class=\"btn btn-default dropdown-toggle sort-fields\" data-toggle=dropdown aria-haspopup=true aria-expanded=false>{{config.currentField.title}} <span class=caret></span></button><ul class=dropdown-menu><li ng-repeat=\"item in config.fields\" ng-class=\"{'selected': item === config.currentField}\"><a class=sort-field role=menuitem tabindex=-1 ng-click=selectField(item)>{{item.title}}</a></li></ul></div><a><i class=sort-direction ng-class=getSortIconClass() ng-click=changeDirection()></i></a></div></div></form></div>"
4038
+ ) ;
4039
+
3796
4040
} ] ) ;
3797
4041
; angular . module ( 'patternfly.views' ) . run ( [ '$templateCache' , function ( $templateCache ) {
3798
4042
'use strict' ;
0 commit comments