Abstract out an expiration status view into its own component
This commit is contained in:
		
							parent
							
								
									c5d8b5f86b
								
							
						
					
					
						commit
						977539bf08
					
				
					 7 changed files with 78 additions and 48 deletions
				
			
		|  | @ -0,0 +1,10 @@ | |||
| <span class="expiration-status-view-element"> | ||||
|   <span ng-if="::$ctrl.expirationDate" ng-class="::$ctrl.getExpirationInfo($ctrl.expirationDate).className" data-title="{{ $ctrl.expirationDate | amDateFormat:'dddd, MMMM Do YYYY, h:mm:ss a' }}" bs-tooltip> | ||||
|       <i class="fa" ng-class="::$ctrl.getExpirationInfo($ctrl.expirationDate).icon"></i> | ||||
|       <span am-time-ago="$ctrl.expirationDate"></span> | ||||
|     </a> | ||||
|   </span> | ||||
|   <span class="no-expiration" ng-if="::!$ctrl.expirationDate"> | ||||
|     Never | ||||
|   </span> | ||||
| </span> | ||||
|  | @ -0,0 +1,34 @@ | |||
| import { Input, Component, Inject } from 'ng-metadata/core'; | ||||
| import * as moment from "moment"; | ||||
| 
 | ||||
| /** | ||||
|  * A component that displays expiration status. | ||||
|  */ | ||||
| @Component({ | ||||
|   selector: 'expiration-status-view', | ||||
|   templateUrl: '/static/js/directives/ui/expiration-status-view/expiration-status-view.component.html', | ||||
| }) | ||||
| export class ExpirationStatusViewComponent { | ||||
|   @Input('<') public expirationDate: Date; | ||||
| 
 | ||||
|   private getExpirationInfo(expirationDate): any { | ||||
|     if (!expirationDate) { | ||||
|       return ''; | ||||
|     } | ||||
| 
 | ||||
|     var expiration_date = moment(expirationDate); | ||||
|     if (moment().isAfter(expiration_date)) { | ||||
|       return {'className': 'expired', 'icon': 'fa-warning'}; | ||||
|     } | ||||
| 
 | ||||
|     if (moment().add(1, 'week').isAfter(expiration_date)) { | ||||
|       return {'className': 'critical', 'icon': 'fa-warning'}; | ||||
|     } | ||||
| 
 | ||||
|     if (moment().add(1, 'month').isAfter(expiration_date)) { | ||||
|       return {'className': 'warning', 'icon': 'fa-warning'}; | ||||
|     } | ||||
| 
 | ||||
|     return {'className': 'info', 'icon': 'fa-clock-o'}; | ||||
|   } | ||||
| } | ||||
|  | @ -80,32 +80,19 @@ angular.module('quay').directive('serviceKeysManager', function () { | |||
|         return moment(key.created_date).add(key.rotation_duration, 's').format('LLL'); | ||||
|       }; | ||||
| 
 | ||||
|       $scope.getExpirationInfo = function(key) { | ||||
|       $scope.willRotate = function(key) { | ||||
|         if (!key.expiration_date) { | ||||
|           return ''; | ||||
|           return false; | ||||
|         } | ||||
| 
 | ||||
|         if (key.rotation_duration) { | ||||
|           var rotate_date = moment(key.created_date).add(key.rotation_duration, 's') | ||||
|           if (moment().isBefore(rotate_date)) { | ||||
|             return {'className': 'rotation', 'icon': 'fa-refresh', 'willRotate': true}; | ||||
|             return true; | ||||
|           } | ||||
|         } | ||||
| 
 | ||||
|         expiration_date = moment(key.expiration_date); | ||||
|         if (moment().isAfter(expiration_date)) { | ||||
|           return {'className': 'expired', 'icon': 'fa-warning'}; | ||||
|         } | ||||
| 
 | ||||
|         if (moment().add(1, 'week').isAfter(expiration_date)) { | ||||
|           return {'className': 'critical', 'icon': 'fa-warning'}; | ||||
|         } | ||||
| 
 | ||||
|         if (moment().add(1, 'month').isAfter(expiration_date)) { | ||||
|           return {'className': 'warning', 'icon': 'fa-warning'}; | ||||
|         } | ||||
| 
 | ||||
|         return {'className': 'info', 'icon': 'fa-check'}; | ||||
|         return false; | ||||
|       }; | ||||
| 
 | ||||
|       $scope.showChangeName = function(key) { | ||||
|  |  | |||
|  | @ -31,6 +31,7 @@ import { MarkdownToolbarComponent } from './directives/ui/markdown/markdown-tool | |||
| import { MarkdownEditorComponent } from './directives/ui/markdown/markdown-editor.component'; | ||||
| import { DockerfileCommandComponent } from './directives/ui/dockerfile-command/dockerfile-command.component'; | ||||
| import { ImageCommandComponent } from './directives/ui/image-command/image-command.component'; | ||||
| import { ExpirationStatusViewComponent } from './directives/ui/expiration-status-view/expiration-status-view.component'; | ||||
| import { BrowserPlatform, browserPlatform } from './constants/platform.constant'; | ||||
| import { ManageTriggerComponent } from './directives/ui/manage-trigger/manage-trigger.component'; | ||||
| import { ClipboardCopyDirective } from './directives/ui/clipboard-copy/clipboard-copy.directive'; | ||||
|  | @ -74,6 +75,7 @@ import * as Clipboard from 'clipboard'; | |||
|     ImageCommandComponent, | ||||
|     TypeaheadDirective, | ||||
|     ManageTriggerComponent, | ||||
|     ExpirationStatusViewComponent, | ||||
|     ClipboardCopyDirective, | ||||
|     TriggerDescriptionComponent, | ||||
|   ], | ||||
|  |  | |||
		Reference in a new issue