Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refatoraçoes pequenas #66

Merged
merged 7 commits into from
Feb 14, 2024
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
8 changes: 4 additions & 4 deletions src/components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@
import _ from 'lodash'
import draggable from 'vuedraggable'
import { NextAPI } from '../services/NextAPI'
import matriculaUtils from '../utils/Matricula'
import { ufabcMatricula } from '../services/UFABCMatricula'
import { convertDisciplina } from '../utils/convertUfabcDisciplina'
import { findSeasonKey, findIdeais } from '../utils/season'

const nextApi = NextAPI();
const nextApi = new NextAPI().init();

export default {
name: 'Modal',
Expand Down Expand Up @@ -207,7 +207,7 @@
fetch() {
let corteId = _.get(this.value, 'corte_id', '')
if(!corteId) return
const aluno_id = matriculaUtils.getAlunoId()
const aluno_id = ufabcMatricula.getAlunoId()

this.loading = true

Expand Down Expand Up @@ -266,7 +266,7 @@
// },

tableRowClassName({row, rowIndex}) {
if (row.aluno_id == matriculaUtils.getAlunoId()) {
if (row.aluno_id == ufabcMatricula.getAlunoId()) {
return 'aluno-row'
} else if(rowIndex <= this.computeKicksForecast) {
return 'not-kicked-row'
Expand Down
2 changes: 1 addition & 1 deletion src/components/ReviewSubject.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
series: []
};

const nextApi = NextAPI();
const nextApi = new NextAPI().init();

export default {
name: 'ReviewSubject',
Expand Down
10 changes: 5 additions & 5 deletions src/components/ReviewTeacher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ import Highcharts from "highcharts";

import _ from "lodash";
import { NextAPI } from "../services/NextAPI";
import Utils from "../utils/extensionUtils";
import matriculaUtils from "../utils/Matricula";
import { NextStorage } from "../services/NextStorage";
import { ufabcMatricula } from "../services/UFABCMatricula";

Highcharts3D(Highcharts);

Expand Down Expand Up @@ -147,7 +147,7 @@ const data = {
series: [],
};

const nextApi = NextAPI();
const nextApi = new NextAPI().init();

export default {
name: "ReviewTecher",
Expand Down Expand Up @@ -334,8 +334,8 @@ export default {
fetchStudent() {
let self = this;

const storageUser = "ufabc-extension-" + matriculaUtils.currentUser();
Utils.storage.getItem(storageUser).then((item) => {
const storageUser = "ufabc-extension-" + ufabcMatricula.currentUser();
NextStorage.getItem(storageUser).then((item) => {
if (item == null) return;
self.student_cr = _.get(item, "[1].cr", 0) || _.get(item, "[0].cr", 0);
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/init.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Utils from "../utils/extensionUtils";
import { extensionUtils } from "../utils/extensionUtils";

xdLocalStorage.init({
/* required */
iframeUrl: Utils.getExtensionUrl("pages/iframe.html"),
iframeUrl: extensionUtils.extensionURL("pages/iframe.html"),
//an option function to be called right after the iframe was loaded and ready for action
initCallback: function () {
console.log("Got iframe ready");
Expand Down
23 changes: 12 additions & 11 deletions src/scripts/contentScriptPortal.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import toastr from "toastr";
import $ from "jquery";
import _ from "lodash";
import Utils from "../utils/extensionUtils";
import { extensionUtils } from "../utils/extensionUtils";
import { NextAPI } from "../services/NextAPI";
import { NextStorage } from "../services/NextStorage";
import Axios from "axios";
import Toastify from "toastify-js";

const getURL = chrome.runtime.getURL ?? ((path) => path);

const nextApi = NextAPI();
const nextApi = new NextAPI().init();

const toast = new Toastify({
text: `
Expand Down Expand Up @@ -43,19 +44,19 @@ if (isPortalAluno) {
anchor.setAttribute("id", "app");
document.body.append(anchor);

Utils.injectStyle("styles/portal.css");
extensionUtils.injectStyle("styles/portal.css");

toastr.info(
"Clique em <a href='https://aluno.ufabc.edu.br/fichas_individuais' style='color: #FFF !important;'>Ficha Individual</a> para atualizar suas informações!"
);
} else if (isFichasIndividuais) {
Utils.injectStyle("styles/portal.css");
extensionUtils.injectStyle("styles/portal.css");

toast.showToast();

iterateTabelaCursosAndSaveToLocalStorage();
} else if (isStudentFicha) {
Utils.injectStyle("styles/portal.css");
extensionUtils.injectStyle("styles/portal.css");
}

function iterateTabelaCursosAndSaveToLocalStorage() {
Expand Down Expand Up @@ -101,7 +102,7 @@ async function getFichaAluno(fichaAlunoUrl, nomeDoCurso, anoDaGrade) {
)[1] || "some ra";

const storageRA = "ufabc-extension-ra-" + getEmailAluno();
await Utils.storage.setItem(storageRA, ra);
await NextStorage.setItem(storageRA, ra);

const jsonFicha = await Axios.get(
"https://aluno.ufabc.edu.br" + fichaAlunoUrl,
Expand Down Expand Up @@ -203,13 +204,13 @@ function toNumber(el) {

async function saveToLocalStorage(curso) {
const storageUser = "ufabc-extension-" + getEmailAluno();
let user = await Utils.storage.getItem(storageUser);
let user = await NextStorage.getItem(storageUser);
if (!user || _.isEmpty(user)) user = [];

user.push(curso);
user = _.uniqBy(user, "curso");

await Utils.storage.setItem(storageUser, user);
await NextStorage.setItem(storageUser, user);

toastr.success(
`Suas informações foram salvas! Disciplinas do curso do ${curso.curso}
Expand All @@ -221,11 +222,11 @@ async function saveToLocalStorage(curso) {

async function saveStudentsToLocalStorage(curso) {
const storageUser = "ufabc-extension-" + getEmailAluno();
const cursos = await Utils.storage.getItem(storageUser);
const cursos = await NextStorage.getItem(storageUser);
const ra = (curso && curso.ra) || null;

let allSavedStudents = [];
const students = await Utils.storage.getItem("ufabc-extension-students");
const students = await NextStorage.getItem("ufabc-extension-students");
if (students && students.length) {
allSavedStudents.push(...students);
}
Expand All @@ -238,5 +239,5 @@ async function saveStudentsToLocalStorage(curso) {
lastUpdate: Date.now(),
};
allSavedStudents.unshift(student);
await Utils.storage.setItem("ufabc-extension-students", allSavedStudents);
await NextStorage.setItem("ufabc-extension-students", allSavedStudents);
}
35 changes: 14 additions & 21 deletions src/scripts/contentscript.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
// https://crx.dam.io/ext/gphjopenfpnlnffmhhhhdiecgdcopmhk.html
// add extension id to window
const isBrowser = typeof chrome != "undefined" && !!chrome.storage;
// var script = document.createElement('script');
// const extension_id = isBrowser ? chrome.i18n.getMessage("@@extension_id") : null;
// script.innerHTML = `extension_id = "${extension_id}"`;
// (document.head || document.documentElement).appendChild(script)
// CSS imports
import "element-ui/lib/theme-chalk/index.css";

import $ from "jquery";
import _ from "lodash";

import matriculaUtils from "../utils/Matricula";
import { ufabcMatricula } from "../services/UFABCMatricula";
import { setupStorage } from "../utils/setupStorage";
import { extensionUtils } from "../utils/extensionUtils";
import { NextStorage } from "../services/NextStorage";

import Utils from "../utils/extensionUtils";

// CSS imports
import "element-ui/lib/theme-chalk/index.css";

const isBrowser = typeof chrome != "undefined" && !!chrome.storage;
let matricula_url;

if (process.env.NODE_ENV == "production") {
Expand Down Expand Up @@ -49,9 +42,9 @@ if (!isBrowser) {
async function load() {
const currentUrl = document.location.href;
// add cross-domain local storage
Utils.injectScript("lib/xdLocalStorage.min.js");
Utils.injectIframe("pages/iframe.html");
Utils.injectScript("lib/init.js");
extensionUtils.injectScript("lib/xdLocalStorage.min.js");
extensionUtils.injectIframe("pages/iframe.html");
extensionUtils.injectScript("lib/init.js");

setupStorage();
await import("./contentScriptPortal");
Expand All @@ -61,11 +54,11 @@ async function load() {
setTimeout(async () => {
let lastUpdate = null;
try {
lastUpdate = await Utils.storage.getItem("ufabc-extension-last");
lastUpdate = await NextStorage.getItem("ufabc-extension-last");
} catch (err) {
lastUpdate = Date.now();
} finally {
matriculaUtils.updateProfessors(lastUpdate);
ufabcMatricula.updateProfessors(lastUpdate);
}

// this is the main vue app
Expand All @@ -75,10 +68,10 @@ async function load() {
$("#meio").prepend(anchor);

//inject styles
Utils.injectStyle("styles/main.css");
extensionUtils.injectStyle("styles/main.css");

// manda as informacoes para o servidor
matriculaUtils.sendAlunoData();
ufabcMatricula.sendAlunoData();

// load vue app modal
const modal = document.createElement("div");
Expand All @@ -99,7 +92,7 @@ async function load() {
document.body.append(reviewSubject);

// inject Vue app
Utils.injectScript("scripts/main.js");
extensionUtils.injectScript("scripts/main.js");
}, 1500);
}
}
37 changes: 25 additions & 12 deletions src/services/NextAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,30 @@ function resolveEndpoint(env) {
);
}

export function NextAPI() {
const baseURL = resolveEndpoint(process.env.NODE_ENV);
const REQUEST_TIMEOUT = 5000;
const nextAPI = Axios.create({
baseURL,
timeout: REQUEST_TIMEOUT,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
});
export class NextAPI {
static #nextApiInstance;
#baseURL = resolveEndpoint("prod");
#REQUEST_TIMEOUT = 5_000;
#DEFAULT_HEADERS = {
Accept: "application/json",
"Content-Type": "application/json",
};

return nextAPI;
static nextInstance() {
if (!NextAPI.#nextApiInstance) {
NextAPI.#nextApiInstance = new NextAPI();
}

return NextAPI.#nextApiInstance;
}

init() {
const nextApi = Axios.create({
baseURL: this.#baseURL,
timeout: this.#REQUEST_TIMEOUT,
headers: this.#DEFAULT_HEADERS,
});

return nextApi;
}
}
Loading