Skip to content

Commit

Permalink
feat(ember): adjusted project-form to allow using access tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Feb 19, 2024
1 parent f968c59 commit 0bd790f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ember/app/components/project-form/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default class ProjectFormComponent extends Component {
saveProject = dropTask(async () => {
try {
if (this.project.repoType === 'public') {
this.project.accessToken = '';
}
const project = await this.project.save({
adapterOptions: {
include:
Expand Down Expand Up @@ -61,6 +65,7 @@ export default class ProjectFormComponent extends Component {
});
this.router.transitionTo('projects.detailed', project.id);
this.project.accessToken = '';
this.notification.success('Successfully saved!');
} catch (e) {
this.notification.danger(e);
Expand All @@ -79,4 +84,8 @@ export default class ProjectFormComponent extends Component {
get users() {
return this.store.peekAll('user');
}
get repoTypes() {
return ['public', 'access-token'];
}
}
20 changes: 19 additions & 1 deletion ember/app/components/project-form/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,25 @@
as |f|
>
<f.input @name="name" />
<f.input @name="repo" />
<div class="uk-margin">
<label class="uk-form-label">Repo</label>
<div class="repo-inputs">
<f.input @name="repo" @raw={{true}} />
<f.input
@name="repoType"
@type="select"
@options={{this.repoTypes}}
@raw={{true}}
/>
</div>
</div>

<f.input
@name="accessToken"
type="password"
autocomplete="off"
@hidden={{(eq this.project.repoType "public")}}
/>

<f.input
@name="users"
Expand Down
16 changes: 16 additions & 0 deletions ember/app/styles/components/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,19 @@
.is-invalid:focus {
border: $form-border-width solid $form-danger-color;
}

.repo-inputs {
display: flex;

& > div:first-of-type {
width: 90%;
}

& > div:last-of-type {
min-width: 8rem;
display: grid;
align-content: start;
width: 100%;
flex-shrink: 9;
}
}
19 changes: 17 additions & 2 deletions ember/app/validations/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@ import {
validatePresence,
validateLength,
validateFormat,
validateInclusion,
} from 'ember-changeset-validations/validators';

import validationsWhenOther from 'outdated/utils/validations-when-other';

export default {
name: [validatePresence(true), validateLength({ max: 100 })],
name: [
validatePresence({ presence: true, ignoreBlank: true }),
validateLength({ max: 100 }),
],
repoType: [validatePresence(true)],
repo: [
validatePresence(true),
validatePresence({ presence: true, ignoreBlank: true }),
validateLength({ max: 200 }),
validateFormat({
regex: /^([-_\w]+\.[-._\w]+)\/([-_\w]+)\/([-_\w]+)$/,
}),
],
accessToken: validationsWhenOther({
field: 'repoType',
otherFieldValidator: validateInclusion({ in: ['access-token'] }),
fieldValidators: [
validatePresence({ presence: true, ignoreBlank: true }),
validateFormat({ regex: /^[-_a-zA-Z\d]*$/ }),
],
}),
maintainers: [],
};

0 comments on commit 0bd790f

Please sign in to comment.