Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DamianoNaraku committed Sep 15, 2023
2 parents a9318bc + 0136690 commit 8defcb0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
REACT_APP_TEST = "http://localhost:3000/memorec/"
REACT_APP_MEMOREC = "http://localhost:8080"

2 changes: 1 addition & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1 +1 @@
REACT_APP_TEST = "http://localhost:3000/memorec/"
REACT_APP_MEMOREC = "http://localhost:8080"
2 changes: 1 addition & 1 deletion src/components/toolbar/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function ContextMenuComponent(props: AllProps) {
{(memorec && memorec.data?.map((obj, index) => {
return (<div key={index}>
<div className={"col item2"} onClick={() => setSuggestedName(obj.recommendedItem)}>
{obj.recommendedItem} : {obj.score}
{obj.recommendedItem} : {Math.round(obj.score * 100) / 100}
</div>
</div>)
})) }
Expand Down
18 changes: 5 additions & 13 deletions src/memorec/api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import axios, {AxiosRequestConfig, AxiosResponse} from 'axios';
import {GObject, LModelElement, LNamedElement, U} from "../joiner";
import axios, {AxiosResponse} from 'axios';
import {GObject, LModelElement, LNamedElement} from "../joiner";
import {MemoRecModel, MemoRecNamed, MemoRecObject} from "./types";

/*
per cors policy il client deve mandare richieste allo stesso server.
quindi le deve mandare a node.js e node.js server deve rimandarle a spring con un proxy server
*/

export default class MemoRec {
static async post(path: string, obj: MemoRecObject): Promise<AxiosResponse> {
console.clear();
return await axios.post('/' + path, obj);
console.log(obj);
return await axios.post('/memorec/' + path, obj);
}

static async structuralFeature(me: LModelElement): Promise<{data:GObject[], type:'class'|'package'}> {
Expand All @@ -21,7 +16,6 @@ export default class MemoRec {
const model = me.model;
const classes = model.classes;


const memorecClasses: MemoRecNamed[] = [];

for(let myClass of classes) {
Expand All @@ -38,10 +32,9 @@ export default class MemoRec {
const response = await MemoRec.post('structuralFeatures', memorecObject);
console.log(response);

const data:GObject[] = response.data.slice(0, 10);
const data: GObject[] = response.data.slice(0, 10);
data.sort((a,b) => b.score - a.score);

// SetRootFieldAction.new('memorec', {data: response.data, type: 'class'});
return {data: data, type: 'class'};

}
Expand All @@ -68,7 +61,6 @@ export default class MemoRec {

const data:GObject[] = response.data.slice(0, 10);
data.sort((a,b) => b.score - a.score);
//SetRootFieldAction.new('memorec', {data: response.data, type: 'package'}); //setta l'oggetto memorec
return {data: data, type: 'package'};
}
}
15 changes: 4 additions & 11 deletions src/setupProxy.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
const { createProxyMiddleware } = require('http-proxy-middleware');
const {createProxyMiddleware} = require('http-proxy-middleware');

module.exports = function (app) {
app.use(
'/classes',
'/memorec/*',
createProxyMiddleware({
target: 'http://localhost:8080',
changeOrigin: true,
})
);
app.use(
'/structuralFeatures',
createProxyMiddleware({
target: 'http://localhost:8080',
changeOrigin: true,
target: process.env['REACT_APP_MEMOREC'],
changeOrigin: true
})
);
};

0 comments on commit 8defcb0

Please sign in to comment.