Skip to content

Commit

Permalink
Update 'absoluteUrl' function
Browse files Browse the repository at this point in the history
  • Loading branch information
kravets-levko committed Feb 20, 2018
1 parent 0465958 commit 8cd758c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
5 changes: 3 additions & 2 deletions client/app/pages/users/new.js
@@ -1,6 +1,7 @@
import { absoluteUrl } from '@/services/utils';
import template from './new.html';

function NewUserCtrl($scope, Utils, toastr, currentUser, Events, User) {
function NewUserCtrl($scope, toastr, currentUser, Events, User) {
Events.record('view', 'page', 'users/new');

$scope.inviteLink = '';
Expand All @@ -14,7 +15,7 @@ function NewUserCtrl($scope, Utils, toastr, currentUser, Events, User) {
$scope.user.$save((user) => {
$scope.user = user;
$scope.user.created = true;
$scope.inviteLink = Utils.absoluteUrl(user.invite_link);
$scope.inviteLink = absoluteUrl(user.invite_link);
toastr.success('Saved.');
}, (error) => {
const message = error.data.message || 'Failed saving.';
Expand Down
5 changes: 3 additions & 2 deletions client/app/pages/users/show.js
@@ -1,11 +1,12 @@
import { each } from 'underscore';
import settingsMenu from '@/lib/settings-menu';
import { absoluteUrl } from '@/services/utils';
import template from './show.html';
import './settings.less';

function UserCtrl(
$scope, $routeParams, $http, $location, toastr,
clientConfig, currentUser, Events, User, Utils,
clientConfig, currentUser, Events, User,
) {
$scope.userId = $routeParams.userId;
$scope.currentUser = currentUser;
Expand Down Expand Up @@ -104,7 +105,7 @@ function UserCtrl(
$scope.disablePasswordResetButton = true;
$http.post(`api/users/${$scope.user.id}/reset_password`).success((data) => {
$scope.disablePasswordResetButton = false;
$scope.passwordResetLink = Utils.absoluteUrl(data.reset_link);
$scope.passwordResetLink = absoluteUrl(data.reset_link);
});
};
}
Expand Down
18 changes: 6 additions & 12 deletions client/app/services/utils.js
@@ -1,14 +1,8 @@
function absoluteUrl(url) {
const location = window.location;
/* eslint-disable import/prefer-default-export */

const scheme = location.protocol.toLowerCase();
const host = location.host;

return scheme + '//' + host + url;
}

export default function init(ngModule) {
ngModule.factory('Utils', () => ({
absoluteUrl,
}));
export function absoluteUrl(url) {
const urlObj = new URL(url, window.location);
urlObj.protocol = window.location.protocol;
urlObj.host = window.location.host;
return urlObj.toString();
}

0 comments on commit 8cd758c

Please sign in to comment.