Skip to content

Commit

Permalink
free of bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tevko committed Dec 16, 2024
1 parent 6d80224 commit 4a9a729
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 59 deletions.
17 changes: 11 additions & 6 deletions client-report/src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const App = (props) => {
const [groupNames, setGroupNames] = useState(null);
const [repfulAgreeTidsByGroup, setRepfulAgreeTidsByGroup] = useState(null);
const[repfulDisageeTidsByGroup, setRepfulDisageeTidsByGroup] = useState(null);
const [formatTid, setFormatTid] = useState(null);
const [formatTid, setFormatTid] = useState(() => v => v);
const [report, setReport] = useState(null);
const [computedStats, setComputedStats] = useState(null);
const [nothingToShow, setNothingToShow] = useState(true);
Expand Down Expand Up @@ -301,7 +301,7 @@ const App = (props) => {
var _filteredProbabilities = {};

// prep Correlation matrix.
if (globals.enableMatrix) {
if (globals.enableMatrix && correlationHClust) {
var probabilities = correlationHClust.matrix;
var tids = correlationHClust.comments;
for (let row = 0; row < probabilities.length; row++) {
Expand Down Expand Up @@ -429,12 +429,13 @@ const App = (props) => {
setGroupNames(_groupNames);
setRepfulAgreeTidsByGroup(_repfulAgreeTidsByGroup);
setRepfulDisageeTidsByGroup(_repfulDisageeTidsByGroup);
setFormatTid(_formatTid);
setFormatTid(() => _formatTid);
setReport(_report);
setComputedStats(_computedStats);
setNothingToShow(!comments.length || !_groupDemographics.length);
setNothingToShow(!_comments.length || !_groupDemographics.length);
})
.catch((err) => {
console.error(err);
setError(true);
setErrorText(String(err));
});
Expand Down Expand Up @@ -462,6 +463,7 @@ const App = (props) => {
resizeTimeout = setTimeout(handleResize, 500);
});
init();
console.log("calling init")
}, []);

const onAutoRefreshEnabled = () => {
Expand Down Expand Up @@ -510,6 +512,8 @@ const App = (props) => {
);
}

console.log("FORMATTID", typeof formatTid)

return (
<div style={{ margin: "0px 10px" }} data-testid="reports-overview">
<Heading conversation={conversation} />
Expand All @@ -536,7 +540,7 @@ const App = (props) => {
comments={comments}
ptptCount={ptptCount}
ptptCountTotal={ptptCountTotal}
demographics={demographics}
demographics={groupDemographics}
conversation={conversation}
voteColors={voteColors}
/>
Expand Down Expand Up @@ -581,6 +585,7 @@ const App = (props) => {
probabilities={filteredCorrelationMatrix}
probabilitiesTids={filteredCorrelationTids}
voteColors={voteColors}
formatTid={formatTid}
/>
<MajorityStrict
math={math}
Expand All @@ -594,7 +599,7 @@ const App = (props) => {
<ParticipantGroups
comments={comments}
conversation={conversation}
demographics={demographics}
demographics={groupDemographics}
ptptCount={ptptCount}
groupNames={groupNames}
formatTid={formatTid}
Expand Down
178 changes: 125 additions & 53 deletions client-report/src/util/net.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,144 @@
// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
// // Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import URLs from "./url";
// import URLs from "./url";

// var urlPrefix = URLs.urlPrefix;

// function polisAjax(api, data, type) {
// if (typeof api !== "string") {
// throw "api param should be a string";
// }

// if (api && api.length && api[0] === '/') {
// api = api.slice(1);
// }

// var url = urlPrefix + api;

// // Add the auth token if needed.
// // if (_.contains(authenticatedCalls, api)) {
// // var token = tokenStore.get();
// // if (!token) {
// // needAuthCallbacks.fire();
// // console.error("auth needed");
// // return $.Deferred().reject("auth needed");
// // }
// // //data = $.extend({ token: token}, data); // moving to cookies
// // }

// var promise;
// var config = {
// url: url,
// contentType: "application/json; charset=utf-8",
// headers: {
// //"Cache-Control": "no-cache" // no-cache
// "Cache-Control": "max-age=0"
// },
// xhrFields: {
// withCredentials: true
// },
// // crossDomain: true,
// dataType: "json"
// };
// if ("GET" === type) {
// promise = $.ajax($.extend(config, {
// type: "GET",
// data: data
// }));
// } else if ("POST" === type) {
// promise = $.ajax($.extend(config, {
// type: "POST",
// data: JSON.stringify(data)
// }));
// }

// promise.fail( function(jqXHR/*, message, errorType*/) {

// // sendEvent("Error", api, jqXHR.status);

// // logger.error("SEND ERROR");
// console.dir(arguments);
// if (403 === jqXHR.status) {
// // eb.trigger(eb.authNeeded);
// }
// //logger.dir(data);
// //logger.dir(message);
// //logger.dir(errorType);
// });
// return promise;
// }

// function polisPost(api, data) {
// return polisAjax(api, data, "POST");
// }

var urlPrefix = URLs.urlPrefix;
// function polisGet(api, data) {
// return polisAjax(api, data, "GET");
// }

// var pid = "unknownpid";
// const PolisNet = {
// polisAjax: polisAjax,
// polisPost: polisPost,
// polisGet: polisGet,
// };
// export default PolisNet;

// Copyright (C) 2012-present, The Authors. This program is free software: you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public License, version 3, as published by the
// Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Affero General Public License for more details. You should have received a copy of the
// GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

import URLs from "./url";

const urlPrefix = URLs.urlPrefix;

function polisAjax(api, data, type) {
if (!_.isString(api)) {
if (typeof api !== "string") {
throw "api param should be a string";
}

if (api && api.length && api[0] === '/') {
api = api.slice(1);
}

var url = urlPrefix + api;

// Add the auth token if needed.
// if (_.contains(authenticatedCalls, api)) {
// var token = tokenStore.get();
// if (!token) {
// needAuthCallbacks.fire();
// console.error("auth needed");
// return $.Deferred().reject("auth needed");
// }
// //data = $.extend({ token: token}, data); // moving to cookies
// }

var promise;
var config = {
url: url,
contentType: "application/json; charset=utf-8",
let url = urlPrefix + api;

const options = {
method: type,
headers: {
//"Cache-Control": "no-cache" // no-cache
"Cache-Control": "max-age=0"
"Content-Type": "application/json; charset=utf-8",
"Cache-Control": "max-age=0",
},
xhrFields: {
withCredentials: true
},
// crossDomain: true,
dataType: "json"
credentials: "include", // This sends cookies with the request
};
if ("GET" === type) {
promise = $.ajax($.extend(config, {
type: "GET",
data: data
}));
} else if ("POST" === type) {
promise = $.ajax($.extend(config, {
type: "POST",
data: JSON.stringify(data)
}));
}

promise.fail( function(jqXHR/*, message, errorType*/) {

// sendEvent("Error", api, jqXHR.status);
if (type === "POST") {
options.body = JSON.stringify(data);
} else if (type === "GET" && data) {
// Add data as query parameters for GET requests
const queryParams = new URLSearchParams(data);
url += `?${queryParams}`;
}

// logger.error("SEND ERROR");
console.dir(arguments);
if (403 === jqXHR.status) {
// eb.trigger(eb.authNeeded);
}
//logger.dir(data);
//logger.dir(message);
//logger.dir(errorType);
});
return promise;
return fetch(url, options)
.then(response => {
if (!response.ok) {
// Handle error responses (e.g., 403)
console.error("Error:", response.status, response.statusText);
if (response.status === 403) {
// eb.trigger(eb.authNeeded);
}
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.catch(error => {
console.error("Fetch error:", error);
// Handle fetch errors
throw error;
});
}

function polisPost(api, data) {
Expand All @@ -83,5 +154,6 @@ const PolisNet = {
polisPost: polisPost,
polisGet: polisGet,
};

export default PolisNet;

0 comments on commit 4a9a729

Please sign in to comment.