Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brunoocasali/65dcefa5c7560c24015bd385f702eb86 to your computer and use it in GitHub Desktop.
Save brunoocasali/65dcefa5c7560c24015bd385f702eb86 to your computer and use it in GitHub Desktop.
---
app/controllers/companies/edit.js | 31 ++
app/services/active-storage.js | 16 +
app/templates/companies/edit.hbs | 87 +---
config/environment.js | 10 +-
package.json | 1 +
yarn.lock | 705 +++++++++++++++++++++++++++++-
6 files changed, 768 insertions(+), 82 deletions(-)
create mode 100644 app/controllers/companies/edit.js
create mode 100644 app/services/active-storage.js
diff --git a/app/controllers/companies/edit.js b/app/controllers/companies/edit.js
new file mode 100644
index 0000000..9b71c95
--- /dev/null
+++ b/app/controllers/companies/edit.js
@@ -0,0 +1,31 @@
+import Controller from "@ember/controller";
+import { inject as service } from "@ember/service";
+import { tracked } from '@glimmer/tracking';
+import { action } from '@ember/object';
+
+export default class CompaniesEditController extends Controller {
+ @service activeStorage;
+ @service filters;
+
+ // @tracked currentPage = 1;
+ @tracked uploadProgress = 1;
+ @tracked id = 1;
+
+ @action upload({ target }) {
+ const { files } = target;
+ const file = files.item(0);
+
+ this.activeStorage
+ .upload(file, {
+ onProgress: (progress) => {
+ console.log(progress);
+ this.uploadProgress = progress;
+ },
+ })
+ .then((blob) => {
+ const signedId = blob.signedId;
+
+ this.id = signedId;
+ });
+ }
+}
diff --git a/app/services/active-storage.js b/app/services/active-storage.js
new file mode 100644
index 0000000..fceac60
--- /dev/null
+++ b/app/services/active-storage.js
@@ -0,0 +1,16 @@
+import ActiveStorage from '@algonauti/ember-active-storage/services/active-storage';
+import { inject as service } from '@ember/service';
+
+export default class ActiveStorageService extends ActiveStorage {
+ @service session;
+
+ get headers() {
+ const headers = {};
+
+ if (this.session.isAuthenticated) {
+ headers.authorization = `Bearer ${this.session.data.authenticated.token}`;
+ }
+
+ return headers;
+ }
+}
diff --git a/app/templates/companies/edit.hbs b/app/templates/companies/edit.hbs
index 87576f8..a54f820 100644
--- a/app/templates/companies/edit.hbs
+++ b/app/templates/companies/edit.hbs
@@ -1,88 +1,25 @@
-<div>
+<div class="main">
<Navbar>
<h1>
Backstage
</h1>
<p>
- Edição de Empresas
+ Edição de empresas
</p>
</Navbar>
- <section>
- <div>
- <form>
- <div>
- <div>
- <label for="grid-name">
- Nome da Empresa
- </label>
- <input id="grid-name" type="text" placeholder="ACME Company Inc." value={{@model.name}}>
- </div>
- <div>
- <label for="grid-url">
- URL
- </label>
- <input id="grid-url" type="text" placeholder="mycompanyurl.url.co" value={{@model.url}}>
- </div>
- </div>
- <div>
- <div>
- <label for="grid-cnpj">
- CNPJ
- </label>
- <input id="grid-cnpj" type="text" placeholder="21.685.000/00001-13" value={{@model.cnpj}}>
- </div>
- <div>
- <label for="grid-platform">
- Plataforma
- </label>
-
- <Companies::DashDataLoader
- @path="platforms" as |loader|
- >
- <select>
- {{#if loader.isRunning}}
- <option value="" disabled>Carregando...</option>
- {{else}}
- <option value=""></option>
- {{#each loader.data as |item|}}
- <option value={{item.id}} selected={{eq @model.platformId item.id}}>
- {{item.name}}
- </option>
- {{/each}}
- {{/if}}
- </select>
- </Companies::DashDataLoader>
- </div>
+ <section class="main">
+ <div class="companies wrapper">
+ <div class="container">
+ <h4>{{@model.name}}</h4>
+ <small>Migração de produtos da empresa.</small>
- <div>
- <label for="grid-segment">
- Segmento
- </label>
-
- <Companies::DashDataLoader
- @path="segments" as |loader|
- >
- <select>
- {{#if loader.isRunning}}
- <option value="" disabled>Carregando...</option>
- {{else}}
- <option value=""></option>
- {{#each loader.data as |item|}}
- <option value={{item.id}} selected={{eq @model.segmentId item.id}}>
- {{item.name}}
- </option>
- {{/each}}
- {{/if}}
- </select>
- </Companies::DashDataLoader>
- </div>
+ <div style="margin-top: 10px;">
+ <label for="file">arquivo</label>
+ <input name="file" type="file" {{on "change" (fn this.upload)}} />
</div>
-
- <button type="button">
- Salvar
- </button>
- </form>
+ <h3>{{this.id}} --- {{this.uploadProgress}}</h3>
+ </div>
</div>
</section>
diff --git a/config/environment.js b/config/environment.js
index d43a270..4934beb 100644
--- a/config/environment.js
+++ b/config/environment.js
@@ -65,8 +65,14 @@ module.exports = function(environment) {
}
if (environment === 'production') {
- ENV.apollo.apiURL = 'https://backstage-api.trustvox.com.br/graphql';
- ENV.dash.apiURL = 'https://api.trustvox.com.br/public/backstage';
+ }
+
+ ENV.apollo.apiURL = 'https://backstage-api.trustvox.com.br/graphql';
+ ENV.dash.apiURL = 'https://api.trustvox.com.br/public/backstage';
+
+ ENV['ember-active-storage'] = {
+ // url: 'https://cargoship.trustvox.com.br/'
+ url: 'http://localhost:3000/api/v1/direct_uploads'
}
return ENV;
diff --git a/package.json b/package.json
index 007dfa9..fe00771 100644
--- a/package.json
+++ b/package.json
@@ -21,6 +21,7 @@
"release": "sh bin/deploy.sh"
},
"devDependencies": {
+ "@algonauti/ember-active-storage": "2.0.2",
"@babel/core": "7.12.9",
"@ember/edition-utils": "1.2.0",
"@ember/optional-features": "2.0.0",
diff --git a/yarn.lock b/yarn.lock
index fbb828b..ef387c2 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -2,6 +2,15 @@
# yarn lockfile v1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment