Skip to content

Commit

Permalink
fix(osSelect): Don't show clear button if no function is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
csnyders committed Mar 15, 2016
1 parent 5e3792c commit ebfa83d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 20 deletions.
49 changes: 49 additions & 0 deletions karma.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
var _ = require("lodash");
var webpack = require('webpack');
var webpackConfig = require("./webpack.config.js");

webpackConfig.devtool = 'inline-source-map';

console.log('webpackConfig', webpackConfig);


module.exports = function(config) {
config.set({
basePath: '.',
frameworks: ['jasmine'],
files: [
'./node_modules/angular/angular.js',
'./node_modules/angular-mocks/angular-mocks.js',
// tests
'test/*_test.js',
'test/**/*_test.js'
],

preprocessors: {
// add webpack as preprocessor
'test/*_test.js': ['webpack'],
'test/**/*_test.js': ['webpack']
},

logLevel: config.LOG_DEBUG,

webpack: webpackConfig,

webpackMiddleware: {
// webpack-dev-middleware configuration
// i. e.
stats: {
colors: true
},
noInfo: false
},
//browsers: ['PhantomJS'],
browsers: ['Chrome'],
plugins: [
"karma-webpack",
"karma-jasmine",
"karma-chrome-launcher",
"karma-phantomjs-launcher"
]
});
};
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
"main": "index.js",
"scripts": {
"build": "typings install & npm run tslint & tsc & webpack & webpack --config webpack.demos.config.js",
"test": "echo \"Error: no test specified\" && exit 0",
"test": "./node_modules/.bin/karma start ./karma.config.js",
"tslint": "tslint \"src/**/*.ts\" || true",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"author": "",
"license": "MIT",
"dependencies": {
"angular-component": "0.0.3",
"lodash": "^4.6.1",
"material-design-lite": "^1.1.1",
"nib": "^1.1.0",
"rx": "^4.0.8",
Expand All @@ -34,6 +35,7 @@
"angular-aria": "^1.4.8",
"angular-material": "^1.0.1",
"angular-messages": "^1.4.8",
"angular-mocks": "^1.5.0",
"angular-sanitize": "^1.4.8",
"condition-circle": "^1.2.0",
"css-loader": "^0.23.1",
Expand All @@ -42,9 +44,18 @@
"jade": "^1.11.0",
"jade-html-loader": "0.0.3",
"jade-loader": "^0.8.0",
"jasmine": "^2.4.1",
"jasmine-core": "^2.4.1",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.2.2",
"karma-jasmine": "^0.3.7",
"karma-phantomjs-launcher": "^1.0.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"less": "^2.5.3",
"less-loader": "^2.2.2",
"openlayers": "~3.8.2",
"phantomjs-prebuilt": "^2.1.5",
"semantic-release": "^4.3.5",
"style-loader": "^0.13.0",
"template-html-loader": "0.0.3",
Expand Down
43 changes: 24 additions & 19 deletions src/components/select/select.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
/// <reference path="../../../typings/main.d.ts" />

export class OsSelect {
static $inject = ['$element'];
static $inject = ['$attrs'];

constructor($element: ng.IRootElementService) {
constructor(private $attrs:ng.IAttributes) {

}

hasCloseExpression() {
return this.$attrs['osClear'];
}

}
}

angular
.module('osElements')
.component('osSelect', {
bindings: {
disabled: '=ngDisabled',
ngModel: '=',
osItems: '=',
placeholder: '@',
displayField: '@osDisplayField',
clear: '&osClear'
},
controller: OsSelect,
controllerAs: 'osSelect',
transclude: false,
template: `
.module('osElements')
.component('osSelect', {
bindings: {
disabled: '=ngDisabled',
ngModel: '=',
osItems: '=',
placeholder: '@',
displayField: '@osDisplayField',
clear: '&osClear'
},
controller: OsSelect,
controllerAs: 'osSelect',
transclude: false,
template: `
<md-select ng-disabled="osSelect.disabled" ng-model="osSelect.ngModel" aria-label="{{osSelect.ngModel[osSelect.displayField]}}" placeholder="{{ osSelect.placeholder }}">
<md-option ng-value="option" ng-disabled="option.disabled" ng-repeat="option in osSelect.osItems">{{ option[osSelect.displayField] }}</md-option>
</md-select>
<os-button ng-if="osSelect.ngModel" class="osSelect__cancel" ng-click="osSelect.clear({object: osSelect.ngModel})" variation="icon"><i class="material-icons">close</i></os-button>
<os-button ng-if="osSelect.ngModel && osSelect.hasCloseExpression()" class="osSelect__cancel" ng-click="osSelect.clear({object: osSelect.ngModel})" variation="icon"><i class="material-icons">close</i></os-button>
`
});
});
16 changes: 16 additions & 0 deletions test/sample_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
describe("sample test", function() {

//beforeEach(angular.mock.module('osElements'));
//
//var $controller;
//
//beforeEach(inject(function(_$controller_){
// $controller = _$controller_;
// console.log('$controller', $controller);
//}));

it("should run another test", function() {
expect(true).toBe(true);
});

});

0 comments on commit ebfa83d

Please sign in to comment.