2017-06-01 20:03:49 +00:00
|
|
|
// Copyright (C) 2017 The Android Open Source Project
|
|
|
|
//
|
|
|
|
// Licensed 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.
|
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Polymer({
|
2017-07-05 17:05:55 -07:00
|
|
|
is: 'gr-create-project-dialog',
|
|
|
|
|
2017-06-01 20:03:49 +00:00
|
|
|
properties: {
|
|
|
|
params: Object,
|
2017-07-05 17:05:55 -07:00
|
|
|
hasNewProjectName: {
|
|
|
|
type: Boolean,
|
|
|
|
notify: true,
|
|
|
|
value: false,
|
|
|
|
},
|
2017-06-01 20:03:49 +00:00
|
|
|
|
2017-08-11 16:32:47 -07:00
|
|
|
/** @type {?} */
|
2017-07-05 17:05:55 -07:00
|
|
|
_projectConfig: {
|
|
|
|
type: Object,
|
2017-12-13 19:09:25 -08:00
|
|
|
value: () => {
|
|
|
|
// Set default values for dropdowns.
|
|
|
|
return {
|
|
|
|
create_empty_commit: false,
|
|
|
|
permissions_only: false,
|
|
|
|
};
|
|
|
|
},
|
2017-07-05 17:05:55 -07:00
|
|
|
},
|
2017-06-01 20:03:49 +00:00
|
|
|
_projectCreated: {
|
2017-08-11 16:32:47 -07:00
|
|
|
type: Boolean,
|
2017-06-01 20:03:49 +00:00
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
_query: {
|
|
|
|
type: Function,
|
|
|
|
value() {
|
|
|
|
return this._getProjectSuggestions.bind(this);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-07-05 17:05:55 -07:00
|
|
|
observers: [
|
|
|
|
'_updateProjectName(_projectConfig.name)',
|
|
|
|
],
|
|
|
|
|
2017-06-01 20:03:49 +00:00
|
|
|
behaviors: [
|
|
|
|
Gerrit.BaseUrlBehavior,
|
|
|
|
Gerrit.URLEncodingBehavior,
|
|
|
|
],
|
|
|
|
|
2017-07-05 17:05:55 -07:00
|
|
|
_computeProjectUrl(projectName) {
|
2017-06-01 20:03:49 +00:00
|
|
|
return this.getBaseUrl() + '/admin/projects/' +
|
|
|
|
this.encodeURL(projectName, true);
|
|
|
|
},
|
|
|
|
|
2017-07-05 17:05:55 -07:00
|
|
|
_updateProjectName(name) {
|
|
|
|
this.hasNewProjectName = !!name;
|
|
|
|
},
|
|
|
|
|
|
|
|
handleCreateProject() {
|
|
|
|
return this.$.restAPI.createProject(this._projectConfig)
|
2017-06-01 20:03:49 +00:00
|
|
|
.then(projectRegistered => {
|
|
|
|
if (projectRegistered.status === 201) {
|
|
|
|
this._projectCreated = true;
|
2017-07-05 17:05:55 -07:00
|
|
|
page.show(this._computeProjectUrl(this._projectConfig.name));
|
2017-06-01 20:03:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_getProjectSuggestions(input) {
|
|
|
|
return this.$.restAPI.getSuggestedProjects(input)
|
|
|
|
.then(response => {
|
|
|
|
const projects = [];
|
|
|
|
for (const key in response) {
|
|
|
|
if (!response.hasOwnProperty(key)) { continue; }
|
|
|
|
projects.push({
|
|
|
|
name: key,
|
|
|
|
value: response[key],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return projects;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2017-07-14 15:20:34 -07:00
|
|
|
})();
|