2018-03-26 10:04:27 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-06-01 20:03:49 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Polymer({
|
2017-11-16 18:54:02 +00:00
|
|
|
is: 'gr-create-repo-dialog',
|
2017-07-05 17:05:55 -07:00
|
|
|
|
2017-06-01 20:03:49 +00:00
|
|
|
properties: {
|
|
|
|
params: Object,
|
2017-11-16 18:54:02 +00:00
|
|
|
hasNewRepoName: {
|
2017-07-05 17:05:55 -07:00
|
|
|
type: Boolean,
|
|
|
|
notify: true,
|
|
|
|
value: false,
|
|
|
|
},
|
2017-06-01 20:03:49 +00:00
|
|
|
|
2017-08-11 16:32:47 -07:00
|
|
|
/** @type {?} */
|
2017-11-16 18:54:02 +00:00
|
|
|
_repoConfig: {
|
2017-07-05 17:05:55 -07:00
|
|
|
type: Object,
|
2017-12-13 19:09:25 -08:00
|
|
|
value: () => {
|
|
|
|
// Set default values for dropdowns.
|
|
|
|
return {
|
2018-02-27 22:46:28 +01:00
|
|
|
create_empty_commit: true,
|
2017-12-13 19:09:25 -08:00
|
|
|
permissions_only: false,
|
|
|
|
};
|
|
|
|
},
|
2017-07-05 17:05:55 -07:00
|
|
|
},
|
2017-11-16 18:54:02 +00:00
|
|
|
_repoCreated: {
|
2017-08-11 16:32:47 -07:00
|
|
|
type: Boolean,
|
2017-06-01 20:03:49 +00:00
|
|
|
value: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
_query: {
|
|
|
|
type: Function,
|
|
|
|
value() {
|
2017-11-16 18:54:02 +00:00
|
|
|
return this._getRepoSuggestions.bind(this);
|
2017-06-01 20:03:49 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2017-07-05 17:05:55 -07:00
|
|
|
observers: [
|
2017-11-16 18:54:02 +00:00
|
|
|
'_updateRepoName(_repoConfig.name)',
|
2017-07-05 17:05:55 -07:00
|
|
|
],
|
|
|
|
|
2017-06-01 20:03:49 +00:00
|
|
|
behaviors: [
|
|
|
|
Gerrit.BaseUrlBehavior,
|
|
|
|
Gerrit.URLEncodingBehavior,
|
|
|
|
],
|
|
|
|
|
2017-11-16 18:54:02 +00:00
|
|
|
_computeRepoUrl(repoName) {
|
|
|
|
return this.getBaseUrl() + '/admin/repos/' +
|
|
|
|
this.encodeURL(repoName, true);
|
2017-06-01 20:03:49 +00:00
|
|
|
},
|
|
|
|
|
2017-11-16 18:54:02 +00:00
|
|
|
_updateRepoName(name) {
|
|
|
|
this.hasNewRepoName = !!name;
|
2017-07-05 17:05:55 -07:00
|
|
|
},
|
|
|
|
|
2017-11-16 18:54:02 +00:00
|
|
|
handleCreateRepo() {
|
|
|
|
return this.$.restAPI.createRepo(this._repoConfig)
|
|
|
|
.then(repoRegistered => {
|
|
|
|
if (repoRegistered.status === 201) {
|
|
|
|
this._repoCreated = true;
|
|
|
|
page.show(this._computeRepoUrl(this._repoConfig.name));
|
2017-06-01 20:03:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-11-16 18:54:02 +00:00
|
|
|
_getRepoSuggestions(input) {
|
2017-06-01 20:03:49 +00:00
|
|
|
return this.$.restAPI.getSuggestedProjects(input)
|
|
|
|
.then(response => {
|
2017-11-16 18:54:02 +00:00
|
|
|
const repos = [];
|
2017-06-01 20:03:49 +00:00
|
|
|
for (const key in response) {
|
|
|
|
if (!response.hasOwnProperty(key)) { continue; }
|
2017-11-16 18:54:02 +00:00
|
|
|
repos.push({
|
2017-06-01 20:03:49 +00:00
|
|
|
name: key,
|
|
|
|
value: response[key],
|
|
|
|
});
|
|
|
|
}
|
2017-11-16 18:54:02 +00:00
|
|
|
return repos;
|
2017-06-01 20:03:49 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2017-07-14 15:20:34 -07:00
|
|
|
})();
|