TEZ-2984. Tez UI 2: Create abstract classes (sree)
Project: http://git-wip-us.apache.org/repos/asf/tez/repo Commit: http://git-wip-us.apache.org/repos/asf/tez/commit/95c13aaa Tree: http://git-wip-us.apache.org/repos/asf/tez/tree/95c13aaa Diff: http://git-wip-us.apache.org/repos/asf/tez/diff/95c13aaa Branch: refs/heads/TEZ-2980 Commit: 95c13aaafd0e7791e7abd94ebd774d2ea7af019a Parents: ec0a592 Author: Sreenath Somarajapuram <[email protected]> Authored: Wed Dec 30 16:59:14 2015 +0530 Committer: Sreenath Somarajapuram <[email protected]> Committed: Thu Feb 25 03:31:59 2016 +0530 ---------------------------------------------------------------------- TEZ-2980-CHANGES.txt | 1 + .../src/main/webapp/app/adapters/abstract.js | 54 ++++++++++++++++++++ .../webapp/app/initializers/local-storage.js | 26 ++++++++++ tez-ui2/src/main/webapp/app/models/abstract.js | 33 ++++++++++++ tez-ui2/src/main/webapp/app/routes/abstract.js | 32 ++++++++++++ .../src/main/webapp/app/serializers/abstract.js | 26 ++++++++++ .../main/webapp/app/services/local-storage.js | 39 ++++++++++++++ tez-ui2/src/main/webapp/bower.json | 3 +- tez-ui2/src/main/webapp/ember-cli-build.js | 2 + .../webapp/tests/unit/adapters/abstract-test.js | 39 ++++++++++++++ .../unit/initializers/local-storage-test.js | 39 ++++++++++++++ .../webapp/tests/unit/models/abstract-test.js | 29 +++++++++++ .../webapp/tests/unit/routes/abstract-test.js | 29 +++++++++++ .../tests/unit/serializers/abstract-test.js | 31 +++++++++++ .../webapp/tests/unit/services/hosts-test.js | 1 - .../tests/unit/services/local-storage-test.js | 42 +++++++++++++++ 16 files changed, 424 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/TEZ-2980-CHANGES.txt ---------------------------------------------------------------------- diff --git a/TEZ-2980-CHANGES.txt b/TEZ-2980-CHANGES.txt index 5143309..e3fece1 100644 --- a/TEZ-2980-CHANGES.txt +++ b/TEZ-2980-CHANGES.txt @@ -4,3 +4,4 @@ ALL CHANGES: TEZ-2983. Tez UI 2: Get ember initializers functional TEZ-3018. Tez UI 2: Add config.env TEZ-3019. Tez UI 2: Replace BaseURL with Host + TEZ-2984. Tez UI 2: Create abstract classes http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/app/adapters/abstract.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/adapters/abstract.js b/tez-ui2/src/main/webapp/app/adapters/abstract.js new file mode 100644 index 0000000..aca0faf --- /dev/null +++ b/tez-ui2/src/main/webapp/app/adapters/abstract.js @@ -0,0 +1,54 @@ +/*global more*/ + +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; +import DS from 'ember-data'; + +var MoreString = more.String; + +export default DS.RESTAdapter.extend({ + ajax: function(url, method, hash) { + return this._super(url, method, Ember.$.extend(hash || {}, { + crossDomain: true, + xhrFields: { + withCredentials: true + } + })); + }, + buildURL: function(type, id, record) { + var url = this._super(type, undefined, record); + return MoreString.fmt(url, record); + }, + findQuery: function(store, type, query) { + var record = query.metadata; + delete query.metadata; + + return this.ajax(this.buildURL( + Ember.String.pluralize(type.typeKey), + record.id, + Ember.Object.create(record) + ), + 'GET', + { + data: query + } + ); + } +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/app/initializers/local-storage.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/initializers/local-storage.js b/tez-ui2/src/main/webapp/app/initializers/local-storage.js new file mode 100644 index 0000000..8504c35 --- /dev/null +++ b/tez-ui2/src/main/webapp/app/initializers/local-storage.js @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function initialize(application) { + application.inject('controller', 'localStorage', 'service:localStorage'); +} + +export default { + name: 'local-storage', + initialize +}; http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/app/models/abstract.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/models/abstract.js b/tez-ui2/src/main/webapp/app/models/abstract.js new file mode 100644 index 0000000..2191d18 --- /dev/null +++ b/tez-ui2/src/main/webapp/app/models/abstract.js @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import DS from 'ember-data'; + +export default DS.Model.extend({ + timeStamp: null, + + refreshTimestamp: function () { + this.set('timeStamp', new Date()); + }, + + actions: { + didUpdate: function () { + this.refreshTimestamp(); + } + } +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/app/routes/abstract.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/routes/abstract.js b/tez-ui2/src/main/webapp/app/routes/abstract.js new file mode 100644 index 0000000..a4d2bb5 --- /dev/null +++ b/tez-ui2/src/main/webapp/app/routes/abstract.js @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; + +export default Ember.Route.extend({ + title: null, // Must be set by inheriting class + + setDocTitle: function () { + Ember.$(document).attr('title', this.get('title')); + }, + + setupController: function (controller, model) { + this._super(controller, model); + this.setDocTitle(); + } +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/app/serializers/abstract.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/serializers/abstract.js b/tez-ui2/src/main/webapp/app/serializers/abstract.js new file mode 100644 index 0000000..c032c30 --- /dev/null +++ b/tez-ui2/src/main/webapp/app/serializers/abstract.js @@ -0,0 +1,26 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; +import DS from 'ember-data'; + +export default DS.RESTSerializer.extend({ + normalize: function(type, hash /*, prop */) { + return Ember.JsonMapper.map(hash, this.get('map')); + } +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/app/services/local-storage.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/app/services/local-storage.js b/tez-ui2/src/main/webapp/app/services/local-storage.js new file mode 100644 index 0000000..d25ef9d --- /dev/null +++ b/tez-ui2/src/main/webapp/app/services/local-storage.js @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; + +export default Ember.Service.extend({ + getStoreKey: function (key) { + return "tez-ui:" + key; + }, + set: function (key, value) { + try { + localStorage.setItem(this.getStoreKey(key) , JSON.stringify(value)); + }catch(e){ + return e; + } + return value; + }, + get: function (key) { + try { + return JSON.parse(localStorage.getItem(this.getStoreKey(key))); + }catch(e){} + return undefined; + } +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/bower.json ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/bower.json b/tez-ui2/src/main/webapp/bower.json index b6c7ca5..98402b3 100644 --- a/tez-ui2/src/main/webapp/bower.json +++ b/tez-ui2/src/main/webapp/bower.json @@ -11,6 +11,7 @@ "jquery": "^1.11.3", "loader.js": "3.3.0", "qunit": "~1.19.0", - "jquery-ui": "~1.11.4" + "jquery-ui": "~1.11.4", + "more-js": "*" } } http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/ember-cli-build.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/ember-cli-build.js b/tez-ui2/src/main/webapp/ember-cli-build.js index ede63b3..c68e22b 100644 --- a/tez-ui2/src/main/webapp/ember-cli-build.js +++ b/tez-ui2/src/main/webapp/ember-cli-build.js @@ -34,5 +34,7 @@ module.exports = function(defaults) { app.import('bower_components/jquery-ui/jquery-ui.js'); app.import('bower_components/jquery-ui/ui/tooltip.js'); + app.import('bower_components/more-js/dist/more.js'); + return app.toTree(extraAssets); }; http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/adapters/abstract-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/adapters/abstract-test.js b/tez-ui2/src/main/webapp/tests/unit/adapters/abstract-test.js new file mode 100644 index 0000000..00be0ac --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/adapters/abstract-test.js @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('adapter:abstract', 'Unit | Adapter | abstract', { + // Specify the other units that are required for this test. + // needs: ['serializer:foo'] +}); + +test('Basic creation', function(assert) { + let adapter = this.subject(); + + assert.ok(adapter); +}); + +test('buildURL test', function(assert) { + let adapter = this.subject(); + + assert.equal(adapter.buildURL("{x}/{y}/type", null, { + x: "x_x", + y: "y_y" + }), "/x_x/y_y/types"); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/initializers/local-storage-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/initializers/local-storage-test.js b/tez-ui2/src/main/webapp/tests/unit/initializers/local-storage-test.js new file mode 100644 index 0000000..f600fdc --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/initializers/local-storage-test.js @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Ember from 'ember'; +import LocalStorageInitializer from '../../../initializers/local-storage'; +import { module, test } from 'qunit'; + +let application; + +module('Unit | Initializer | local storage', { + beforeEach() { + Ember.run(function() { + application = Ember.Application.create(); + application.deferReadiness(); + }); + } +}); + +test('it works', function(assert) { + LocalStorageInitializer.initialize(application); + + // you would normally confirm the results of the initializer here + assert.ok(true); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/models/abstract-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/models/abstract-test.js b/tez-ui2/src/main/webapp/tests/unit/models/abstract-test.js new file mode 100644 index 0000000..42fe21c --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/models/abstract-test.js @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('abstract', 'Unit | Model | abstract', { + // Specify the other units that are required for this test. + needs: [] +}); + +test('Basic test for existence', function(assert) { + let model = this.subject(); + assert.ok(model); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/routes/abstract-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/routes/abstract-test.js b/tez-ui2/src/main/webapp/tests/unit/routes/abstract-test.js new file mode 100644 index 0000000..e11183e --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/routes/abstract-test.js @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:abstract', 'Unit | Route | abstract', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('Basic test for existence', function(assert) { + let route = this.subject(); + assert.ok(route); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/serializers/abstract-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/serializers/abstract-test.js b/tez-ui2/src/main/webapp/tests/unit/serializers/abstract-test.js new file mode 100644 index 0000000..006d69c --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/serializers/abstract-test.js @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { moduleForModel, test } from 'ember-qunit'; + +moduleForModel('abstract', 'Unit | Serializer | abstract', { + // Specify the other units that are required for this test. + needs: ['serializer:abstract'] +}); + +test('it serializes records', function(assert) { + let record = this.subject(); + let serializedRecord = record.serialize(); + + assert.ok(serializedRecord); +}); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js b/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js index 51b558c..055fccd 100644 --- a/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js +++ b/tez-ui2/src/main/webapp/tests/unit/services/hosts-test.js @@ -23,7 +23,6 @@ moduleFor('service:hosts', 'Unit | Service | hosts', { // needs: ['service:foo'] }); -// Replace this with your real tests. test('Test creation', function(assert) { let service = this.subject(); assert.ok(service); http://git-wip-us.apache.org/repos/asf/tez/blob/95c13aaa/tez-ui2/src/main/webapp/tests/unit/services/local-storage-test.js ---------------------------------------------------------------------- diff --git a/tez-ui2/src/main/webapp/tests/unit/services/local-storage-test.js b/tez-ui2/src/main/webapp/tests/unit/services/local-storage-test.js new file mode 100644 index 0000000..6f9a1af --- /dev/null +++ b/tez-ui2/src/main/webapp/tests/unit/services/local-storage-test.js @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('service:local-storage', 'Unit | Service | local storage', { + // Specify the other units that are required for this test. + // needs: ['service:foo'] +}); + +test('Test creation', function(assert) { + let service = this.subject(); + assert.ok(service); +}); + +test('getStoreKey test', function(assert) { + let service = this.subject(); + + assert.equal(service.getStoreKey("abc"), "tez-ui:abc"); +}); + +test('Set & get test', function(assert) { + let service = this.subject(); + + service.set("abc", "value"); + assert.equal(service.get("abc"), "value"); +});
