-
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.
Fixes #5497
- Loading branch information
Showing
4 changed files
with
79 additions
and
83 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 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,57 +1,55 @@ | ||
define(function (require) { | ||
const app = require('ui/modules').get('kibana'); | ||
|
||
app.directive('share', function (Private) { | ||
const urlShortener = Private(require('./url_shortener')); | ||
|
||
return { | ||
restrict: 'E', | ||
scope: { objectType: '@' }, | ||
template: require('ui/share/index.html'), | ||
controller: function ($scope, $rootScope, $location, $http) { | ||
$scope.shortUrlsLoading = false; | ||
|
||
$scope.$watch('getUrl()', function (url) { | ||
$scope.url = url; | ||
$scope.embedUrl = url.replace('?', '?embed&'); | ||
|
||
//when the url changes we want to hide any generated short urls | ||
$scope.shortenUrls = false; | ||
$scope.shortUrl = undefined; | ||
}); | ||
|
||
$scope.$watch('shortenUrls', enabled => { | ||
if (!!enabled) { | ||
if ($scope.shortUrl) { | ||
const app = require('ui/modules').get('kibana'); | ||
|
||
app.directive('share', function (Private) { | ||
const urlShortener = Private(require('./url_shortener')); | ||
|
||
return { | ||
restrict: 'E', | ||
scope: { objectType: '@' }, | ||
template: require('ui/share/index.html'), | ||
controller: function ($scope, $rootScope, $location, $http) { | ||
$scope.shortUrlsLoading = false; | ||
|
||
$scope.$watch('getUrl()', function (url) { | ||
$scope.url = url; | ||
$scope.embedUrl = url.replace('?', '?embed&'); | ||
|
||
//when the url changes we want to hide any generated short urls | ||
$scope.shortenUrls = false; | ||
$scope.shortUrl = undefined; | ||
}); | ||
|
||
$scope.$watch('shortenUrls', enabled => { | ||
if (!!enabled) { | ||
if ($scope.shortUrl) { | ||
$scope.shortUrlsLoading = false; | ||
} else { | ||
$scope.shortUrlsLoading = true; | ||
|
||
const linkPromise = urlShortener.shortenUrl($scope.url) | ||
.then(shortUrl => { | ||
$scope.shortUrl = shortUrl; | ||
}); | ||
|
||
const embedPromise = urlShortener.shortenUrl($scope.embedUrl) | ||
.then(shortUrl => { | ||
$scope.shortEmbedUrl = shortUrl; | ||
}); | ||
|
||
Promise.all([linkPromise, embedPromise]) | ||
.then(() => { | ||
$scope.shortUrlsLoading = false; | ||
} else { | ||
$scope.shortUrlsLoading = true; | ||
|
||
const linkPromise = urlShortener.shortenUrl($scope.url) | ||
.then(shortUrl => { | ||
$scope.shortUrl = shortUrl; | ||
}); | ||
|
||
const embedPromise = urlShortener.shortenUrl($scope.embedUrl) | ||
.then(shortUrl => { | ||
$scope.shortEmbedUrl = shortUrl; | ||
}); | ||
|
||
Promise.all([linkPromise, embedPromise]) | ||
.then(() => { | ||
$scope.shortUrlsLoading = false; | ||
}) | ||
.catch(err => { | ||
$scope.shortenUrls = false; | ||
}); | ||
} | ||
}) | ||
.catch(err => { | ||
$scope.shortenUrls = false; | ||
}); | ||
} | ||
}); | ||
|
||
$scope.getUrl = function () { | ||
return $location.absUrl(); | ||
}; | ||
} | ||
}; | ||
}); | ||
} | ||
}); | ||
|
||
$scope.getUrl = function () { | ||
return $location.absUrl(); | ||
}; | ||
} | ||
}; | ||
}); |
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,26 +1,24 @@ | ||
define(function (require) { | ||
return function createUrlShortener(Notifier, $http, $location) { | ||
const notify = new Notifier({ | ||
location: 'Url Shortener' | ||
}); | ||
const baseUrl = `${$location.protocol()}://${$location.host()}:${$location.port()}`; | ||
export default function createUrlShortener(Notifier, $http, $location) { | ||
const notify = new Notifier({ | ||
location: 'Url Shortener' | ||
}); | ||
const baseUrl = `${$location.protocol()}://${$location.host()}:${$location.port()}`; | ||
|
||
async function shortenUrl(url) { | ||
const relativeUrl = url.replace(baseUrl, ''); | ||
const formData = { url: relativeUrl }; | ||
async function shortenUrl(url) { | ||
const relativeUrl = url.replace(baseUrl, ''); | ||
const formData = { url: relativeUrl }; | ||
|
||
try { | ||
const result = await $http.post('/shorten', formData); | ||
try { | ||
const result = await $http.post('/shorten', formData); | ||
|
||
return `${baseUrl}/goto/${result.data}`; | ||
} catch (err) { | ||
notify.error(err); | ||
throw err; | ||
} | ||
return `${baseUrl}/goto/${result.data}`; | ||
} catch (err) { | ||
notify.error(err); | ||
throw err; | ||
} | ||
} | ||
|
||
return { | ||
shortenUrl | ||
}; | ||
return { | ||
shortenUrl | ||
}; | ||
}); | ||
}; |