-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from cabidop/remote-fix
Updated remote modal
- Loading branch information
Showing
7 changed files
with
208 additions
and
249 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
assets/javascripts/discourse/components/modal/update-pages-remote.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<DModal | ||
class="update-pages-remote" | ||
@title={{i18n "admin.landing_pages.remote.title"}} | ||
@closeModal={{@closeModal}} | ||
> | ||
<:body> | ||
<div class="repo"> | ||
<div class="label">{{i18n "admin.landing_pages.remote.url"}}</div> | ||
<Input @value={{buffered.url}} placeholder={{urlPlaceholder}} /> | ||
</div> | ||
|
||
<div class="branch"> | ||
<div class="label">{{i18n "admin.customize.theme.remote_branch"}}</div> | ||
<Input @value={{buffered.branch}} placeholder="main" /> | ||
</div> | ||
|
||
<div class="check-private"> | ||
<label> | ||
<Input @type="checkbox" @checked={{buffered.private}} /> | ||
{{i18n "admin.landing_pages.remote.private"}} | ||
</label> | ||
</div> | ||
|
||
{{#if showPublicKey}} | ||
<div class="public-key"> | ||
<div class="label">{{i18n "admin.customize.theme.public_key"}}</div> | ||
<Textarea readonly={{true}} @value={{buffered.public_key}} /> | ||
</div> | ||
{{/if}} | ||
</:body> | ||
|
||
<:footer> | ||
<DButton | ||
@action={{action "update"}} | ||
@disabled={{updateDisabled}} | ||
class="btn btn-primary" | ||
@label="admin.landing_pages.remote.update" | ||
/> | ||
|
||
<DButton | ||
@action={{action "reset"}} | ||
@disabled={{resetDisabled}} | ||
class="btn btn-danger" | ||
@label="admin.landing_pages.remote.reset" | ||
/> | ||
|
||
<DButton | ||
@action={{action "test"}} | ||
@disabled={{testDisabled}} | ||
class="btn btn-test" | ||
@label="admin.landing_pages.remote.test" | ||
/> | ||
|
||
{{#if loading}} | ||
{{loading-spinner size="small"}} | ||
{{else}} | ||
{{#if testIcon}} | ||
{{d-icon testIcon (hash class=tested)}} | ||
{{/if}} | ||
{{/if}} | ||
|
||
<DModalCancel @close={{@closeModal}} /> | ||
</:footer> | ||
</DModal> |
129 changes: 129 additions & 0 deletions
129
assets/javascripts/discourse/components/modal/update-pages-remote.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import Component from "@ember/component"; | ||
import { ajax } from "discourse/lib/ajax"; | ||
import { popupAjaxError } from "discourse/lib/ajax-error"; | ||
import discourseComputed, { observes } from "discourse-common/utils/decorators"; | ||
import { bufferedProperty } from "discourse/mixins/buffered-content"; | ||
import { and, or } from "@ember/object/computed"; | ||
import { action } from "@ember/object"; | ||
|
||
export default Component.extend(bufferedProperty("model.remote"), { | ||
keyGenUrl: "/admin/themes/generate_key_pair", | ||
remoteUrl: "/landing/remote", | ||
httpsPlaceholder: "https://github.com/org/repo", | ||
sshPlaceholder: "[email protected]:org/repo.git", | ||
showPublicKey: and("buffered.private", "buffered.public_key"), | ||
testing: false, | ||
updating: false, | ||
resetting: false, | ||
loading: or("testing", "updating", "resetting"), | ||
|
||
@discourseComputed("tested", "loading") | ||
updateDisabled(tested, loading) { | ||
return tested !== "success" || loading; | ||
}, | ||
|
||
@discourseComputed("buffered.connected", "loading") | ||
resetDisabled(connected, loading) { | ||
return !connected || loading; | ||
}, | ||
|
||
@discourseComputed("buffered.url", "loading") | ||
testDisabled(url, loading) { | ||
return !url || loading; | ||
}, | ||
|
||
@discourseComputed("buffered.private") | ||
urlPlaceholder(isPrivate) { | ||
return isPrivate ? this.sshPlaceholder : this.httpsPlaceholder; | ||
}, | ||
|
||
@discourseComputed("tested") | ||
testIcon(tested) { | ||
return tested === "success" ? "check" : tested === "error" ? "times" : null; | ||
}, | ||
|
||
@observes("buffered.hasChanges") | ||
remoteChanged() { | ||
this.set("tested", null); | ||
}, | ||
|
||
@observes("buffered.private") | ||
privateWasChecked() { | ||
if ( | ||
this.buffered.get("private") && | ||
!this.buffered.get("public_key") && | ||
!this._keyLoading | ||
) { | ||
this.set("_keyLoading", true); | ||
|
||
ajax(this.keyGenUrl, { type: "POST" }) | ||
.then((result) => { | ||
this.buffered.setProperties({ | ||
private_key: result.private_key, | ||
public_key: result.public_key, | ||
}); | ||
}) | ||
.catch(popupAjaxError) | ||
.finally(() => this.set("_keyLoading", false)); | ||
} | ||
}, | ||
|
||
buildData() { | ||
this.commitBuffer(); | ||
const remote = this.model.remote; | ||
return { | ||
remote: { | ||
url: remote.url, | ||
branch: remote.branch, | ||
...(remote.private && { private_key: remote.private_key }), | ||
...(remote.private && { public_key: remote.public_key }), | ||
}, | ||
}; | ||
}, | ||
|
||
@action | ||
test() { | ||
this.set("testing", true); | ||
|
||
ajax(this.remoteUrl + "/test", { | ||
type: "POST", | ||
data: this.buildData(), | ||
}) | ||
.then((result) => { | ||
this.set("tested", result.success ? "success" : "error"); | ||
}) | ||
.catch(popupAjaxError) | ||
.finally(() => this.set("testing", false)); | ||
}, | ||
|
||
@action | ||
update() { | ||
this.set("updating", true); | ||
|
||
ajax(this.remoteUrl, { | ||
type: "PUT", | ||
data: this.buildData(), | ||
}) | ||
.then((result) => { | ||
this.closeModal(result); | ||
this.set("model.remote", {}); | ||
}) | ||
.catch(popupAjaxError) | ||
.finally(() => this.set("updating", false)); | ||
}, | ||
|
||
@action | ||
reset() { | ||
this.set("resetting", true); | ||
|
||
ajax(this.remoteUrl, { | ||
type: "DELETE", | ||
}) | ||
.then(() => { | ||
this.closeModal({ remote: {} }); | ||
this.set("model.remote", {}); | ||
}) | ||
.catch(popupAjaxError) | ||
.finally(() => this.set("resetting", false)); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.