Skip to content

Commit

Permalink
Merge pull request #349 from EthicApp-Development/issue-324-refactor-…
Browse files Browse the repository at this point in the history
…login

Refactoring Frontend Profesor - Issue #324
  • Loading branch information
claudio-alvarez committed Jun 27, 2024
2 parents e0f96fd + 83a2296 commit a0e6fe0
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 105 deletions.
44 changes: 16 additions & 28 deletions ethicapp/frontend/assets/js/controllers/register_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,18 @@ export let RegisterController = ($scope, $http, $translate,apiParams) => {

console.log(userData);

// $http.post("/register", userData)
// .then(function (response) {
// console.log(response);
// if (response.data.success) {
// console.log("Registro exitoso");
// } else {
// console.error("Error en el registro: ");
// }
// })
// .catch(function (error) {
// console.error("Error en la solicitud al backend: " + error);
// });

$http.post("/register", userData)
.then(function (response) {
console.log(response);
if (response.data.success) {
console.log("Registro exitoso");
} else {
console.error("Error en el registro: ");
}
})
.catch(function (error) {
console.error("Error en la solicitud al backend: " + error);
});
};

if (lang.startsWith('es')) {
Expand All @@ -140,36 +139,25 @@ export let RegisterController = ($scope, $http, $translate,apiParams) => {
self.getcountries();
};

self.activate_user = function(){
var url_string = window.location;
var url = new URL(url_string);
var token = url.searchParams.get("tok");
//console.log(token);
$http({ url: "activate_user", method: "post",data: {token} }).success(function () {
});
};

self.getcountries = function(){
$http.get("https://restcountries.com/v3.1/all").success(function (data) {
var list = [];

for(var i = 0;i< data.length;i++){
list.push(data[i].name.common);
}
list.sort();
if(lang[0] == "e" && lang[1] == "s"){
if(self.lang == "ES_CL/spanish"){
list.unshift("Elige un Pais");
}
else{
list.unshift("Choose Country");
}

self.countries = list;

});
};



self.init();
};
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ app.controller(
// };

self.loadDocuments = function () {
var postdata = { dsgnid: self.designId};
var postdata = { designId: self.designId};
$http({
url: "designs-documents", method: "post", data: postdata
}).success(function (data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ app.controller("RoleController", ["$scope", "$http", "$timeout", "$socket", "Not
};

self.loadDocuments = function () {
var postdata = { dsgnid: self.designId};
var postdata = { designId: self.designId};
$http({
url: "designs-documents", method: "post", data: postdata
}).success(function (data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export let ActivityController = ($scope, ActivitiesService,

self.openActivity = (activityId) => {
let promises = [];

// Step 1: look up the activity
promises.push(() => {
return ActivitiesService.lookUpActivity(activityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export let DesignsDocController = ($scope, DesignsService, DocumentsService,
};

self.requestDesignDocuments = () => {
var postdata = { dsgnid: DesignsService.workingDesignId };
var postdata = { designId: DesignsService.workingDesignId };
$http({
url: "designs-documents", method: "post", data: postdata
}).success(function (data) {
Expand All @@ -54,7 +54,7 @@ export let DesignsDocController = ($scope, DesignsService, DocumentsService,
};

self.deleteDesignDocument = (designId) => {
let postdata = { dsgnid: designId };
let postdata = { designId: designId };
$http({
url: "delete-design-document", method: "post", data: postdata
}).success(function () {
Expand Down
52 changes: 15 additions & 37 deletions ethicapp/frontend/assets/js/controllers/teacher/home_controller.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
/*eslint func-style: ["error", "expression"]*/
export let HomeController = ($scope,
TabStateService, DesignsService, ActivitiesService,
$http, $uibModal, $location, $locale,
$filter, $socket, $route, $translate) => {
TabStateService, ActivitiesService,
$socket, $route, $translate) => {

var self = $scope;
self.shared = {};
// [DEPRECATED] self.misc = {};
// [DEPRECATED] self.temp = "";
// [DEPRECATED] self.sessions = [];
// [DEPRECATED] self.currentActivity = {}; //current Activity
// [DEPRECATED] self.design = null;
// [DEPRECATED] self.selectedSes = null;
// [DEPRECATED] self.documents = [];
// [DEPRECATED] self.questions = [];
// [DEPRECATED] self.questionTexts = [];
// [DEPRECATED] self.newUsers = [];
// [DEPRECATED] self.users = {};
// [DEPRECATED] self.selectedId = -1;
// [DEPRECATED] self.role = "A";
// [DEPRECATED] self.sesStatusses = ["notPublicada", "reading", "personal", "anon", "teamWork", "finished"];
// [DEPRECATED] self.optConfidence = [0, 25, 50, 75, 100];
// [DEPRECATED] self.iterationNames = [];
// [DEPRECATED] self.showSeslist = true;
// [DEPRECATED] self.superBar = false;
// [DEPRECATED] self.institution = false;
// [DEPRECATED] self.inst_id = 0;

self.init = function () {
self.tabSel = TabStateService.sharedTabState;
Expand Down Expand Up @@ -78,20 +57,19 @@ export let HomeController = ($scope,
if(tab != self.selectedView){
self.selectedView = tab;
$route.reload();
/*
if (tab != "editDesign" && tab != "viewDesign"){
// Avoids making designs-documents request
self.designId.id = null;
}
if (tab != "launchActivity") {
self.launchId.id = null;
self.launchId.title = null;
self.launchId.type = null;
}
if (tab == "designs") {
if(type != null) self.tabSel.type = type;
else self.tabSel.type = 0;
}*/
// if (tab != "editDesign" && tab != "viewDesign"){
// // Avoids making designs-documents request
// self.designId.id = null;
// }
// if (tab != "launchActivity") {
// self.launchId.id = null;
// self.launchId.title = null;
// self.launchId.type = null;
// }
// if (tab == "designs") {
// if(type != null) self.tabSel.type = type;
// else self.tabSel.type = 0;
// }
}
};

Expand Down
13 changes: 5 additions & 8 deletions ethicapp/frontend/assets/js/ngmodules/teacher/teacher_admin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var adpp = angular.module("Admin", ["ngSanitize", "btford.socket-io",
"api-params", "ui.bootstrap", "ui.multiselect", "nvd3", "timer",
"ui-notification", "ngQuill", "tableSort", "pascalprecht.translate",
"ngRoute", "checklist-model", "ngDialog"]

).factory("TabStateService", function() {
// Maintains the state of the main tab view of the UI
var service = {};
Expand All @@ -20,7 +21,6 @@ var adpp = angular.module("Admin", ["ngSanitize", "btford.socket-io",
.factory("DocumentsService", ["$rootScope", "$http", DocumentsService]);

import { ActivityController } from "../../controllers/teacher/activity_controller.js";
import { StagesController } from "../../controllers/teacher/stages_controller.js";
import { BrowseDesignsController } from "../../controllers/teacher/browse_designs_controller.js";
import { ConfirmModalController } from "../../controllers/teacher/confirm_modal_controller.js";
import { ContentModalController } from "../../controllers/teacher/content_modal_controller.js";
Expand All @@ -33,7 +33,7 @@ import { TabsController } from "../../controllers/tabs_controller.js";
import { MonitorActivityController } from "../../controllers/teacher/monitor_activity_controller.js";
import { RoutingController } from "../../controllers/teacher/routing_controller.js";
import { DesignEditorController } from "../../controllers/teacher/design_editor_controller.js";
import { ngQuillConfigProvider } from "../../helpers/util.js";
import { ngQuillConfigProvider } from "/js/helpers/util.js";

adpp.factory("$socket", ["socketFactory", function (socketFactory) {
return socketFactory();
Expand Down Expand Up @@ -77,10 +77,8 @@ adpp.config(["$provide", function($provide) {
adpp.controller("RoutingController",
["$scope", RoutingController]);
adpp.controller("HomeController",
["$scope", "TabStateService", "DesignsService",
"ActivitiesService",
"$http", "$uibModal", "$location", "$locale",
"$filter", "$socket", "$route", "$translate", HomeController]);
["$scope", "TabStateService", "ActivitiesService",
"$socket", "$route", "$translate", HomeController]);
adpp.controller("TabsController",
["$scope", "$http", "Notification", TabsController]);
adpp.controller("NewUsersController",
Expand All @@ -96,14 +94,13 @@ adpp.controller("GroupController",
adpp.controller("DesignsDocController",
["$scope", "DesignsService", "DocumentsService", "$http", "Notification", "$timeout", DesignsDocController]);
adpp.controller("ActivityController",
["$scope", "ActivitiesService", "DesignsService", "SesionsService", "DocumentsService", "$filter", "$http", "Notification", "$timeout", ActivityController]);
["$scope", "ActivitiesService", "DesignsService", "SessionsService", "DocumentsService", "$filter", "$http", "Notification", "$timeout", ActivityController]);
adpp.controller("MonitorActivityController",
["$scope", "$filter", "$http", "$window", "Notification","$uibModal", MonitorActivityController]);
adpp.controller("BrowseDesignsController",
["$scope", "TabStateService", "DesignsService", "ActivitiesService", "$filter", "$http", BrowseDesignsController]);
adpp.controller("DesignEditorController",
["$scope", "DesignsService", "ActivitiesService", "$filter", "$http", "Notification", "$timeout", DesignEditorController]);
adpp.controller("StagesController", ["$scope", "$http", "Notification", "$uibModal", StagesController]);

adpp.service("DialogService", function(ngDialog) {
this.openDialog = function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as apiMod from "./activities_service/factories/api_object_factory.js";
import * as cp from "./activities_service/plugins/content_plugin_registry.js";
import * as apiMod from "/js/services/teacher/activities_service_plugins/factories/api_object_factories.js";
import * as cp from "/js/services/teacher/activities_service_plugins/plugins/content_plugin_registry.js";

export let ActivitiesService = ($rootScope, $http) => {
let service = { };
Expand Down Expand Up @@ -36,20 +36,19 @@ export let ActivitiesService = ($rootScope, $http) => {

service.currentActivity = activity;
// Set the current content plugin
service.setContentPlugin(activity.design.metainfo.type);

service.setContentPlugin(activity.design.type);
$rootScope.$broadcast("ActivitiesService_currentActivityUpdated",
service.currentActivity);
};

service.setContentPlugin = (designType) => {
if (!(designType in cp.contentPluginRegistry)) {
if (!(designType in cp.contentPluginRegistry())) {
let err = `No content plugin found for design type '${designType}'`;
console.error(`[ActivitiesService.setContentPlugin] ${err}`);
throw new Error(err);
}

service.contentPlugin = cp.contentPluginRegistry[designType];
service.contentPlugin = cp.contentPluginRegistry(designType);
};

service.setActivities = (activities) => {
Expand All @@ -63,10 +62,10 @@ export let ActivitiesService = ($rootScope, $http) => {
method: "post",
data: {}
}).then((data) => {
data.activities.map(activity => {
data.data.activities.map(activity => {
activity.title = activity.design.metainfo.title;
});
service.setActivities(data.activities);
service.setActivities(data.data.activities);
}).catch((error) => {
console.log("[ActivitiesService.loadActivities] Error loading activities.");
throw error;
Expand Down Expand Up @@ -98,7 +97,7 @@ export let ActivitiesService = ($rootScope, $http) => {
};

service.createActivity = (sessionId, designId, setAsCurrent = true) => {
var postdata = { sesid: sessionId, dsgnid: designId};
var postdata = { sesid: sessionId, designId: designId};
return $http({ url: "add-activity", method: "post", data: postdata })
.then(result => {
if (setAsCurrent) {
Expand Down
14 changes: 7 additions & 7 deletions ethicapp/frontend/assets/js/services/teacher/designs_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export let DesignsService = ($rootScope, $http) => {
});
};

self.loadPublicDesigns = () => {
service.loadPublicDesigns = () => {
// Get all public designs
return $http.get("get-public-designs").then((data) => {
if (data.status == "ok") {
Expand All @@ -105,7 +105,7 @@ export let DesignsService = ($rootScope, $http) => {
});
};

self.loadUserDesignById = (designId) => {
service.loadUserDesignById = (designId) => {
var postdata = { id: designId };
return $http.post("get-design", postdata)
.then((data) => {
Expand All @@ -120,14 +120,14 @@ export let DesignsService = ($rootScope, $http) => {
}).catch((error) => {
console.log(`[Designs Service] Failed to load design by id:'${designId}'`);
throw new Error(error);
});
});
};

self.importPublicDesignById = (designId) => {
service.importPublicDesignById = (designId) => {
// TODO: implement
};

self.createDesign = (design) => {
service.createDesign = (design) => {
return $http.post("upload-design", design)
.then(function (data) {
if (data.status == "ok") {
Expand All @@ -142,7 +142,7 @@ export let DesignsService = ($rootScope, $http) => {
});
};

self.updateDesign = (designId, design) => {
service.updateDesign = (designId, design) => {
var postdata = {
"design": design,
"id": designId
Expand All @@ -157,7 +157,7 @@ export let DesignsService = ($rootScope, $http) => {
});
};

self.deleteDesign = (designId) => {
service.deleteDesign = (designId) => {
var postdata = { id: designId };
return $http.post("delete-design", postdata).then((data) => {
if (data.status == "ok") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export let DocumentsService = ($rootScope, $http) => {
};

service.loadDesignDocuments = (designId) => {
var postdata = { dsgnid: designId };
var postdata = { designId: designId };
return $http({
url: "designs-documents", method: "post", data: postdata
}).then(function (data) {
Expand All @@ -36,7 +36,7 @@ export let DocumentsService = ($rootScope, $http) => {

service.uploadDesignDocument = (documentData) => {
// NOTE: documentData is actually formData from which the file has been submitted
// The formData object must include a variable containing the design id (dsgnid).
// The formData object must include a variable containing the design id (designId).
return $http.post("upload-design-file", documentData, {
transformRequest: angular.identity,
headers: { "Content-Type": undefined }
Expand All @@ -47,7 +47,7 @@ export let DocumentsService = ($rootScope, $http) => {
};

service.deleteDesignDocument = (designId) => {
let postdata = { dsgnid: designId };
let postdata = { designId: designId };
return $http({
url: "delete-design-document", method: "post", data: postdata
}).then(function () {
Expand Down
5 changes: 1 addition & 4 deletions ethicapp/frontend/assets/libs/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,5 @@ class Socket extends typed_events_1.StrictEventEmitter {
return new broadcast_operator_1.BroadcastOperator(this.adapter, new Set(), new Set([this.id]), flags);
}
}
<<<<<<< HEAD

exports.Socket = Socket;
=======
exports.Socket = Socket;
>>>>>>> frontend_controllers_refactoring
2 changes: 1 addition & 1 deletion ethicapp/frontend/views/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<link rel="stylesheet" href="//cdn.quilljs.com/1.2.0/quill.snow.css" />
<%- include('partials/favicon.ejs') %>
</head>
<body ng-controller="ManagementController">
<body ng-controller="HomeController">
<div class="top-bar-mini cflex" ng-hide="false">
<div class="cf1">
<a href="seslist" class="simple-margin-left">
Expand Down
Loading

0 comments on commit a0e6fe0

Please sign in to comment.