Skip to content
Snippets Groups Projects
Commit e0d629ad authored by Tom Robinson's avatar Tom Robinson
Browse files

Remove unused Angular code and dependencies

parent 32faed37
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,6 @@ import { registerAnalyticsClickListener } from "metabase/lib/analytics";
var Metabase = angular.module('metabase', [
'ngRoute',
'ngCookies',
'ui.bootstrap', // bootstrap LIKE widgets via angular directives
'metabase.auth',
'metabase.filters',
'metabase.directives',
......
/*global setTimeout */
var CardDirectives = angular.module('metabase.card.directives', []);
CardDirectives.directive('mbCardFavoriteButton', ['Card', function(Card) {
function link(scope, element, attr) {
scope.favorite = false;
scope.$watch('cardId', function(value) {
if (value) {
initialize();
}
});
var initialize = function() {
// initialize the current favorite status
Card.isfavorite({
'cardId': scope.cardId
}, function(result) {
if (result && !result.error) {
if (result.favorite === true) {
scope.favorite = true;
}
} else {
console.log(result);
}
});
};
scope.toggleFavorite = function() {
if (scope.favorite) {
// already favorited, lets unfavorite
Card.unfavorite({
'cardId': scope.cardId
}, function(result) {
if (result && !result.error) {
scope.favorite = false;
}
});
} else {
// currently not favorited, lets favorite
Card.favorite({
'cardId': scope.cardId
}, function(result) {
if (result && !result.error) {
scope.favorite = true;
}
});
}
};
}
return {
restrict: 'E',
replace: true,
templateUrl: '/app/card/partials/_card_favorite.html',
scope: {
cardId: '='
},
link: link
};
}]);
......@@ -5,8 +5,7 @@ var Card = angular.module('metabase.card', [
'metabase.filters',
'metabase.directives',
'metabase.services',
'metabase.card.controllers',
'metabase.card.directives'
'metabase.card.controllers'
]);
Card.config(['$routeProvider', function($routeProvider) {
......
......@@ -67,14 +67,4 @@ angular.module('metabase.components')
};
});
angular.module('metabase.components')
.directive('mbLoadingIcon', function () {
return {
restrict: 'E',
templateUrl: '/app/components/icons/loading.html',
scope: ICON_SCOPE,
compile: iconCompile
};
});
}());
......@@ -2,7 +2,7 @@ import Navbar from 'metabase/components/Navbar.jsx';
// Global Controllers
var MetabaseControllers = angular.module('metabase.controllers', ['metabase.services', 'metabase.navbar.directives']);
var MetabaseControllers = angular.module('metabase.controllers', ['metabase.services']);
MetabaseControllers.controller('Metabase', ['$scope', '$location', 'MetabaseCore', 'AppState', function($scope, $location, MetabaseCore, AppState) {
......
......@@ -4,27 +4,9 @@ import ReactDOM from "react-dom";
import { Provider } from 'react-redux';
import { DevTools, DebugPanel } from 'redux-devtools/lib/react';
import ProfileLink from './components/ProfileLink.jsx'
/* Directives */
var MetabaseDirectives = angular.module('metabase.directives', []);
MetabaseDirectives.directive('deleteConfirm', [function() {
return {
priority: 1,
terminal: true,
link: function(scope, element, attr) {
var msg = attr.ngConfirmClick || "Are you sure?";
var clickAction = attr.ngClick;
element.bind('click', function(event) {
if (window.confirm(msg)) {
scope.$eval(clickAction);
}
});
}
};
}]);
MetabaseDirectives.directive('mbDelayedCall', ['$timeout', function($timeout) {
function link(scope, element, attr) {
......@@ -44,95 +26,6 @@ MetabaseDirectives.directive('mbDelayedCall', ['$timeout', function($timeout) {
};
}]);
MetabaseDirectives.directive('mbScrollShadow', [function (){
return {
restrict: 'A',
link: function (scope, element, attr) {
// grab the raw dom element to check its scroll top
var raw = element[0];
element.on('scroll', function () {
if(raw.scrollTop > 0) {
element.addClass('ScrollShadow');
} else {
element.removeClass('ScrollShadow');
}
});
}
};
}]);
MetabaseDirectives.directive('mbActionButton', ['$timeout', '$compile', function ($timeout, $compile) {
return {
restrict: 'A',
scope: {
actionFunction: '=mbActionButton'
},
link: function link(scope, element, attr) {
var defaultText = element.text();
var activeText = attr.activeText;
var failedText = attr.failedText;
var successText = attr.successText;
var fnArg = attr.fnArg;
var delayedReset = function() {
// do we need to have this timeout be configurable?
$timeout(function () {
element.text(defaultText);
element.removeClass('Button--waiting');
element.removeClass('Button--success');
element.removeClass('Button--danger');
element.removeAttr('disabled');
}, 5000);
};
element.bind('click', function (event) {
element.text(activeText);
element.addClass('Button--waiting');
// activate spinner
var loadingIcon = angular.element('<mb-loading-icon width="12px" height="12px"></mb-loading-icon>');
element.append(loadingIcon);
$compile(loadingIcon)(scope);
// disable button
element.attr('disabled', 'true');
// NOTE: we are assuming the action function is a promise
var promise = (fnArg) ? scope.actionFunction(fnArg) : scope.actionFunction();
promise.then(function (result) {
element.text(successText);
element.removeClass('Button--waiting');
element.addClass('Button--success');
var checkIcon = angular.element('<mb-icon name="check" width="12px" height="12px"></mb-icon>');
element.prepend(checkIcon);
$compile(checkIcon)(scope);
// re-activate button
element.removeAttr('disabled');
// timeout, reset to base
delayedReset();
}, function (error) {
element.text(failedText);
element.removeClass('Button--waiting');
element.addClass('Button--danger');
// re-activate button
element.removeAttr('disabled');
// timeout, reset to base
delayedReset();
});
});
}
};
}]);
MetabaseDirectives.directive('mbReduxComponent', ['$timeout', function ($timeout) {
return {
restrict: 'A',
......@@ -219,20 +112,3 @@ MetabaseDirectives.directive('mbReactComponent', ['$timeout', function ($timeout
}
};
}]);
var NavbarDirectives = angular.module('metabase.navbar.directives', []);
NavbarDirectives.directive('mbProfileLink', [function () {
return {
restrict: 'A',
template: '<div mb-react-component="ProfileLink"></div>',
controller: ['$scope', function ($scope) {
$scope.ProfileLink = ProfileLink;
}],
scope: {
context: '=',
user: '='
},
};
}]);
import 'metabase/directives';
describe('metabase.directives', function() {
beforeEach(angular.mock.module('metabase.directives'));
describe('mb-scroll-shadow', function() {
var element;
beforeEach(angular.mock.inject(function($compile, $rootScope) {
element = $compile('<div mb-scroll-shadow style="height: 10px; overflow-y: scroll;"><div style="height: 20px;">x</div></div>')($rootScope);
angular.element(document.body).append(element); // must be added to the body to scrolling stuff to work
}));
it('should not add the ScrollShadow class on scroll if scrollTop is 0', function() {
element[0].scrollTop = 0;
element.triggerHandler('scroll');
expect(element.hasClass('ScrollShadow')).toBe(false);
});
it('should add the ScrollShadow class if scrollTop is greater than 0', function() {
element[0].scrollTop = 5;
element.triggerHandler('scroll');
expect(element.hasClass('ScrollShadow')).toBe(true);
});
it('should remove the ScrollShadow class on scroll if scrollTop is 0', function() {
element.addClass('ScrollShadow');
element[0].scrollTop = 0;
element.triggerHandler('scroll');
expect(element.hasClass('ScrollShadow')).toBe(false);
});
})
});
......@@ -8,11 +8,9 @@ import 'angular-route';
// angular 3rd-party:
import 'angular-cookie';
import 'angular-http-auth'; // currently pulled from unofficial fork: https://github.com/witoldsz/angular-http-auth/pull/100
import 'angular-ui-bootstrap';
import 'angular-http-auth';
// ace:
import 'angular-ui-ace';
import 'ace/ace';
import 'ace/ext-language_tools';
import 'ace/mode-sql';
......
<a href="#" title="Favorite This Question" class="animate-pop" ng-click="toggleFavorite()">
<mb-icon
name="star"
width="18px"
height="18px"
class="text-grey-1"
ng-class="{ 'text-grey-1 text-grey-3-hover' : !favorite,
'text-gold': favorite,
'transition-color': true
}"
>
</mb-icon>
</a>
<div class="my2 border-bottom" ng-model="sql" id="id_sql" rows="10" ui-ace="{ mode: 'sql', onLoad: aceLoaded }"></div>
<svg id="loading" viewBox="0 0 32 32" ng-attr-width="{{width}}" ng-attr-height="{height}}" fill="currentcolor">
<path opacity=".25" d="M16 0 A16 16 0 0 0 16 32 A16 16 0 0 0 16 0 M16 4 A12 12 0 0 1 16 28 A12 12 0 0 1 16 4"/>
<path d="M16 0 A16 16 0 0 1 32 16 L28 16 A12 12 0 0 0 16 4z">
<animateTransform attributeName="transform" type="rotate" from="0 16 16" to="360 16 16" dur="0.8s" repeatCount="indefinite" />
</path>
</svg>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment