-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
and implement new angular style suggestions from Joe
- Loading branch information
1 parent
6b727df
commit 5ca36df
Showing
13 changed files
with
146 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<confirm-dialogue on-confirm="onConfirm()" | ||
on-cancel="onCancel()" | ||
message="{{message}}" | ||
confirm-button-text="{{confirmButtonText}}" | ||
cancel-button-text="{{cancelButtonText}}"> | ||
</confirm-dialogue> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="disable-app-layer"> | ||
<div class="confirm-dialogue" data-test-subj="confirm-dialog"> | ||
<div class="confirm-dialogue__message"> | ||
{{message}} | ||
</div> | ||
<div class="confirm-dialogue__actions"> | ||
<button class="kuiButton kuiButton--primary" | ||
data-test-subj="confirm-dialog-okay-button" | ||
ng-click="onConfirm()">{{confirmButtonText}}</button> | ||
<button class="kuiButton kuiButton--basic" | ||
data-test-subj="confirm-dialog-cancel-button" | ||
ng-click="onCancel()">{{cancelButtonText}}</button> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import uiModules from 'ui/modules'; | ||
import confirmDialogueTemplate from './confirm_dialogue.html'; | ||
|
||
const module = uiModules.get('kibana'); | ||
|
||
module.directive('confirmDialogue', function () { | ||
return { | ||
restrict: 'E', | ||
template: confirmDialogueTemplate, | ||
scope: { | ||
message: '@', | ||
confirmButtonText: '@', | ||
cancelButtonText: '@', | ||
onConfirm: '&', | ||
onCancel: '&' | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './safe_confirm.factory'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import uiModules from 'ui/modules'; | ||
import { ModalDialogue } from './modal_dialogue'; | ||
|
||
const module = uiModules.get('kibana'); | ||
|
||
module.factory('ModalDialogue', function ($rootScope, $compile) { | ||
return class AngularModalDialogue extends ModalDialogue { | ||
constructor(html, scopeObject) { | ||
super(html, scopeObject, $rootScope, $compile); | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import uiModules from 'ui/modules'; | ||
import angular from 'angular'; | ||
|
||
const module = uiModules.get('kibana'); | ||
|
||
module.factory('ModalDialogue', function () { | ||
export class ModalDialogue { | ||
/** | ||
* The only thing this class does is load an element onto the dom when instantiated, | ||
* and removes it when destroy is called. Useful for the modal confirmation dialog. | ||
* Long term, some of the shared modal complexity could be moved in here, hence the name. | ||
* | ||
* @param html | ||
* @param scopeObject | ||
* @param $rootScope | ||
* @param $compile {function} | ||
*/ | ||
return class ModalDialogue { | ||
/** | ||
* | ||
* @param innerElement {HTMLElement} - an element that will be appended to the dom. | ||
*/ | ||
constructor(innerElement) { | ||
this.innerElement = innerElement; | ||
angular.element(document.body).append(this.innerElement); | ||
} | ||
constructor(html, scopeObject, $rootScope, $compile) { | ||
this.modalScope = $rootScope.$new(); | ||
|
||
Object.keys(scopeObject).forEach((key) => { this.modalScope[key] = scopeObject[key]; }); | ||
|
||
this.innerElement = $compile(html)(this.modalScope); | ||
angular.element(document.body).append(this.innerElement); | ||
} | ||
|
||
/** | ||
* Removes the element from the dom. | ||
*/ | ||
destroy() { | ||
this.innerElement.remove(); | ||
} | ||
}; | ||
}); | ||
/** | ||
* Removes the element from the dom. | ||
*/ | ||
destroy() { | ||
this.innerElement.remove(); | ||
this.modalScope.$destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import uiModules from 'ui/modules'; | ||
import { safeConfirm } from './safe_confirm'; | ||
import './directives/confirm_dialogue'; | ||
import './modal_dialogue.factory'; | ||
|
||
const module = uiModules.get('kibana'); | ||
|
||
module.factory('safeConfirm', function ($timeout, ModalDialogue, Promise) { | ||
return (message, confirmButtonText = 'Okay', cancelButtonText = 'Cancel') => | ||
$timeout(() => safeConfirm(message, confirmButtonText, cancelButtonText, Promise, ModalDialogue)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,34 @@ | ||
import uiModules from 'ui/modules'; | ||
uiModules.get('kibana') | ||
import confirmDialogueContainerTemplate from './confirm_dialogue_container.html'; | ||
|
||
/* | ||
* Angular doesn't play well with thread blocking calls such as | ||
* unless those calls are specifically handled inside a call | ||
* to $timeout(). Rather than litter the code with that implementation | ||
* detail, safeConfirm() can be used. | ||
/** | ||
* Shows a modal confirmation dialogue with the given message. | ||
* | ||
* WARNING: safeConfirm only blocks the thread beginning on the next tick. For that reason, a | ||
* promise is returned so consumers can handle the control flow. | ||
* | ||
* Usage: | ||
* safeConfirm('This message will be shown in a modal dialog').then( | ||
* function () { | ||
* // user clicked the okay button | ||
* }, | ||
* function () { | ||
* // user canceled the confirmation | ||
* } | ||
* ); | ||
* @param {String} message | ||
* @param {String} confirmButtonText - Text to show for the button that will resolve the returned promise | ||
* @param {String} cancelButtonText - Text to show for the button that will reject the returned promise | ||
* @param {Promise} Promise - a promise class. | ||
* @param {ModalDialogue} ModalDialogue service | ||
* @return {Promise<boolean>} Returns an angular promise that will be resolved to true if the user | ||
* clicks the yes/okay button and rejected if the user clicks the no/cancel button. | ||
*/ | ||
.factory('safeConfirm', function ($window, $timeout, $q, showConfirmDialogue) { | ||
return function safeConfirm(message) { | ||
return $timeout(function () { | ||
return showConfirmDialogue(message) || $q.reject(false); | ||
}); | ||
}; | ||
}); | ||
export function safeConfirm(message, confirmButtonText, cancelButtonText, Promise, ModalDialogue) { | ||
return new Promise((resolve, reject) => { | ||
let modalDialogue = undefined; | ||
|
||
const dialogueScope = { | ||
onConfirm: () => { | ||
modalDialogue.destroy(); | ||
resolve(true); | ||
}, | ||
onCancel: () => { | ||
modalDialogue.destroy(); | ||
reject(false); | ||
}, | ||
message, | ||
confirmButtonText, | ||
cancelButtonText | ||
}; | ||
|
||
modalDialogue = new ModalDialogue(confirmDialogueContainerTemplate, dialogueScope); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
@import "~ui/styles/variables"; | ||
|
||
.confirm-dialogue { | ||
z-index: 10; | ||
position: absolute; | ||
background-color: white; | ||
left: 40%; | ||
top: 30%; | ||
width: 400px; | ||
padding: 15px 15px 0px 15px; | ||
padding: 15px; | ||
} | ||
|
||
.message { | ||
padding: 0px 0px 5px 0px; | ||
} | ||
.confirm-dialogue__message { | ||
padding: 0px 0px 5px 0px; | ||
} | ||
|
||
.confirm-dialogue__actions { | ||
display: flex; | ||
justify-content: flex-end; | ||
|
||
.form-group { | ||
float: right; | ||
> * + * { | ||
margin-left: 5px; | ||
} | ||
} | ||
|
||
.disable-app-layer { | ||
z-index: 9; | ||
position: absolute; | ||
opacity: .5; | ||
background-color: @kibanaGray1; | ||
height: 100%; | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
position: fixed; | ||
z-index: 10; | ||
background-color: rgba(0, 0, 0, 0.3); | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
right: 0; | ||
padding-bottom: 10vh; | ||
} |