Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 39 additions & 16 deletions packages/rocketchat-apps/client/admin/appInstall.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,56 @@
<template name="appInstall">
<section class="preferences-page">
<header class="preferences-page__header">
{{> burger}}
<a href="{{pathFor "apps"}}" title="{{_ "Back_to_Manage_Apps"}}">
<i class="icon-left-open"></i>
</a> &nbsp;

<h2>{{_ "App_Installation"}}</h2>
</header>
{{> header sectionName="App_Installation" hideHelp=true fixedHeight=true}}
<div class="preferences-page__content">
{{#if isInstalling}}
{{> loading}}
{{else}}
<div class="rc-form-group rc-grid">
<div class="rc-input rc-w50 padded">
<div class="rc-select-avatar__list-item rc-tooltip js-select-app-upload" aria-label="{{_ "Upload_file" }}">
<label class="rc-select-avatar__upload-label app" for="upload-app">
{{> icon block="rc-select-avatar__upload-icon" icon="upload"}}
</label>
<input type="file" name="" value="" id="upload-app" style="display:none;">
</div>
<label class="rc-input__label">
<div class="rc-input__title">{{_ "App_Url_to_Install_From"}}</div>
<div class="rc-input__title">{{>icon icon='clip'}}{{_ "App_Url_to_Install_From"}}</div>
<div class="rc-input__wrapper">
<input type="text" class="rc-input__element" name="appPackageUrl" id="appPackage" placeholder="https://rocket.chat/apps/package.zip" value="{{appUrl}}" >
</div>
</label>
<button class="rc-button install">{{ _ "Install" }}</button>
</div>
<div class="rc-input-file rc-w50 padded">
<label class="rc-input-file__label">
<div class="rc-input-file__title">{{>icon icon='clip'}}{{_ "App_Url_to_Install_From_File"}}</div>
<div class="rc-input-file__wrapper">
<div class="rc-input-file__name">
{{appFile}}
</div>
<input type="file" accept=".zip" class="rc-input-file__element" name="appPackageUrl" id="upload-app" placeholder="https://rocket.chat/apps/package.zip">
<label for='upload-app' class="rc-button rc-button-secondary install">{{_ "Browse_Files"}}</label>
</div>
</label>
<!-- <input type="file" id="file" class="inputfile" onchange='uploadFile(this)'>
<label for="file">
<span id="file-name" class="file-box"></span>
<span class="file-button">
<i class="fa fa-upload" aria-hidden="true"></i>
Select File
</span>
</label>


<label class="rc-input__label">
<div class="rc-input__title">{{>icon icon='clip'}}{{_ "App_Url_to_Install_From_File"}}</div>
<div class="rc-input__wrapper">
</div>
</label> -->
<!-- <div class="rc-select-avatar__list-item rc-tooltip js-select-app-upload" aria-label="{{_ "Upload_file" }}">
<label class="rc-select-avatar__upload-label app" for="upload-app">
{{> icon block="rc-select-avatar__upload-icon" icon="upload"}}
</label>
<input type="file" name="" value="" id="upload-app" style="display:none;">
</div> -->
</div>
</div>
<div class="rc-button-group">
<button class="rc-button rc-button--secondary js-cancel">{{ _ "Cancel" }}</button>
<button class="rc-button rc-button--primary js-install" disabled='{{disabled}}'>{{ _ "Install" }}</button>
</div>
{{/if}}
</div>
Expand Down
39 changes: 30 additions & 9 deletions packages/rocketchat-apps/client/admin/appInstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
// over the passed in body, so if both are found it will only use the url.

Template.appInstall.helpers({
appFile() {
return Template.instance().file.get();
},
isInstalling() {
return Template.instance().isInstalling.get();
},
appUrl() {
return Template.instance().appUrl.get();
},
disabled() {
const instance = Template.instance();
return !(instance.appUrl.get() || instance.file.get());
}
});

Template.appInstall.onCreated(function() {
const instance = this;
instance.file = new ReactiveVar('');
instance.isInstalling = new ReactiveVar(false);
instance.appUrl = new ReactiveVar('');

Expand All @@ -30,19 +38,30 @@ Template.appInstall.onCreated(function() {
});

Template.appInstall.events({
'click .install'(e, t) {
'input #appPackage'(e, i) {
i.appUrl.set(e.currentTarget.value);
},
'change #upload-app'(e, i) {
const file = e.currentTarget.files[0];
i.file.set(file.name);
},
'click .js-cancel'() {
FlowRouter.go('/admin/apps');
},
async 'click .js-install'(e, t) {
const url = $('#appPackage').val().trim();

// Handle url installations
if (url) {
t.isInstalling.set(true);
RocketChat.API.post('apps', { url }).then((result) => {
try {
t.isInstalling.set(true);
const result = await RocketChat.API.post('apps', { url });
FlowRouter.go(`/admin/apps/${ result.app.id }`);
}).catch((err) => {
} catch (err) {
console.warn('err', err);
} finally {
t.isInstalling.set(false);
});

}
return;
}

Expand All @@ -65,11 +84,13 @@ Template.appInstall.events({
}

t.isInstalling.set(true);
RocketChat.API.upload('apps', data).then((result) => {
try {
const result = await RocketChat.API.upload('apps', data);
FlowRouter.go(`/admin/apps/${ result.app.id }`);
}).catch((err) => {
} catch (err) {
console.warn('err', err);
} finally {
t.isInstalling.set(false);
});
}
}
});
Loading