Commit 26b8b2c7 authored by Fabien Amarger's avatar Fabien Amarger
Browse files

[admin] Remove doublon in the researcher list

Sometimes the HTML pages contain a unique researcher several times.
For example if the researcher is a permanent and an invited member
(this situation could happen in the french bizarre administration).
Thanks to this new function we assure that each researcher appears
only once.
parent 335d934b
......@@ -6,7 +6,7 @@ import { ActivatedRoute, Router, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import {Location} from '@angular/common';
import {NgbModal, NgbActiveModal} from '@ng-bootstrap/ng-bootstrap';
import { Title } from '@angular/platform-browser';
import { Title } from '@angular/platform-browser';
import { jqxComboBoxComponent } from 'jqwidgets-framework/jqwidgets-ts/angular_jqxcombobox';
......@@ -29,11 +29,11 @@ declare function escape(s:string): string; // needed for the TS compilation
<p>{{text}}</p>
</div>
<div class="modal-footer">
<div class="col-md-8">êtes-vous sûr ? </div>
<div class="col-md-4">
<button type="button" class="btn btn-outline-success" (click)="activeModal.close(true)">Oui</button>
<button type="button" class="btn btn-outline-danger" (click)="activeModal.close(false)">Non</button>
</div>
<div class="col-md-8">êtes-vous sûr ? </div>
<div class="col-md-4">
<button type="button" class="btn btn-outline-success" (click)="activeModal.close(true)">Oui</button>
<button type="button" class="btn btn-outline-danger" (click)="activeModal.close(false)">Non</button>
</div>
</div>
`
})
......@@ -46,7 +46,7 @@ export class ValidModalContent {
@Component({
selector: 'researcher-list',
providers: [ProxyService, UtilsService],
providers: [ProxyService, UtilsService],
templateUrl: './ResearcherList.component.html',
styleUrls: ['./ResearcherList.component.css']
})
......@@ -56,55 +56,65 @@ export class ResearcherListCmp{
selectedLaboId = -1;
laboId = -1;
researchersListLoading = false;
norm = "EHESS";
normChanging = false;
norm = "EHESS";
normChanging = false;
predefinedResearcherName;
predefinedResearcherName;
selectedResearchers = null;
labos;
preSelected;
nbComputed = 0;
preSelected;
nbComputed = 0;
constructor(private http: HttpClient, private proxy: ProxyService, private utils: UtilsService, private r: ActivatedRoute,private location: Location, private modalService: NgbModal, private title:Title) {
}
initUrlParam(){
let scope = this;
this.r.params.subscribe(function(p){
if(p.labo){
var i = 0;
while (i < scope.labos.length && scope.selectedLaboId == -1){
if(scope.labos[i].name == p.labo){
scope.laboId = i;
}
i++;
}
if(p.researcherName){
scope.predefinedResearcherName = p.researcherName;
}
scope.changeLabo();
}
});
}
ngOnInit() {
this.http.get("assets/labos.json", {
responseType: "json"
}).subscribe(data => {
this.labos = data;
this.initUrlParam();
});
}
initUrlParam(){
let scope = this;
this.r.params.subscribe(function(p){
if(p.labo){
var i = 0;
while (i < scope.labos.length && scope.selectedLaboId == -1){
if(scope.labos[i].name == p.labo){
scope.laboId = i;
}
i++;
}
if(p.researcherName){
scope.predefinedResearcherName = p.researcherName;
}
scope.changeLabo();
}
});
}
ngOnInit() {
this.http.get("assets/labos.json", {
responseType: "json"
}).subscribe(data => {
this.labos = data;
this.initUrlParam();
});
removeDups(researchers) {
const unique = new Map();
researchers.forEach(function(r) {
if(!unique.has(r.name.valName)) {
unique.set(r.name.valName, r)
}
});
return Array.from(unique.values());
}
sortResearchers(researchers){
researchers = this.removeDups(researchers)
var removeDiacritics = this.utils.removeDiacritics;
function compare(a,b) {
var testA = removeDiacritics(a.name.dispName);
......@@ -159,13 +169,13 @@ export class ResearcherListCmp{
this.selectedLaboId = this.laboId;
if(this.selectedLaboId != -1){
this.selectedLabo = this.labos[this.laboId];
this.norm = this.selectedLabo.norm;
if(this.location.path().indexOf(this.selectedLabo.name) == -1){
this.location.replaceState("/admin/"+this.selectedLabo.name);
}
this.norm = this.selectedLabo.norm;
if(this.location.path().indexOf(this.selectedLabo.name) == -1){
this.location.replaceState("/admin/"+this.selectedLabo.name);
}
if(!this.selectedLabo.researchers){
this.researchersListLoading = true;
let predefinedResearcherNameTemp = this.predefinedResearcherName;
let predefinedResearcherNameTemp = this.predefinedResearcherName;
this.http.get(this.proxy.getProxy(this.selectedLabo.url), {
responseType: "text"
}).subscribe(data => {
......@@ -175,147 +185,147 @@ export class ResearcherListCmp{
this.selectedLabo.researchers = this.sortResearchers(researchers);
this.researchersListLoading = false;
if(this.predefinedResearcherName && this.selectedLabo.researchers.length){
let founded = false;
let i = 0;
let foundedResearcher = null;
while(i < this.selectedLabo.researchers.length && !founded){
let researcher = this.selectedLabo.researchers[i];
if(researcher.originalName == this.predefinedResearcherName){
founded = true;
foundedResearcher = researcher;
}
else{
i++;
}
}
if(foundedResearcher){
this.selectedResearchers = [];
this.selectedResearchers.push(foundedResearcher);
this.preSelected = foundedResearcher.originalName;
}
}
if(this.predefinedResearcherName && this.selectedLabo.researchers.length){
let founded = false;
let i = 0;
let foundedResearcher = null;
while(i < this.selectedLabo.researchers.length && !founded){
let researcher = this.selectedLabo.researchers[i];
if(researcher.originalName == this.predefinedResearcherName){
founded = true;
foundedResearcher = researcher;
}
else{
i++;
}
}
if(foundedResearcher){
this.selectedResearchers = [];
this.selectedResearchers.push(foundedResearcher);
this.preSelected = foundedResearcher.originalName;
}
}
});
}
}
else{
this.selectedLabo = null;
this.selectedResearchers = null;
this.location.replaceState("/admin");
this.predefinedResearcherName = null;
this.preSelected = null;
this.selectedResearchers = null;
this.location.replaceState("/admin");
this.predefinedResearcherName = null;
this.preSelected = null;
}
}
comboBoxOnChange(){
let items = this.myComboBox.getSelectedItems();
if(items.length > 0){
this.nbComputed = this.selectedResearchers?this.selectedResearchers.length:0;
this.selectedResearchers = [];
for(let item of items){
this.selectedResearchers.push(item.originalItem);
}
if(this.selectedResearchers.length == 1){
this.location.replaceState("/admin/"+this.selectedLabo.name+"/"+this.selectedResearchers[0].originalName);
}
else{
this.location.replaceState("/admin/"+this.selectedLabo.name+"/");
}
console.log("Selected Researcher : ", this.selectedResearchers);
this.nbComputed = this.selectedResearchers?this.selectedResearchers.length:0;
this.selectedResearchers = [];
for(let item of items){
this.selectedResearchers.push(item.originalItem);
}
if(this.selectedResearchers.length == 1){
this.location.replaceState("/admin/"+this.selectedLabo.name+"/"+this.selectedResearchers[0].originalName);
}
else{
this.location.replaceState("/admin/"+this.selectedLabo.name+"/");
}
console.log("Selected Researcher : ", this.selectedResearchers);
}
else{
this.selectedResearchers = null;
this.selectedResearchers = null;
}
}
clearResearchersList(){
this.preSelected = null;
this.nbComputed = 0;
this.selectedResearchers = [];
this.preSelected = null;
this.nbComputed = 0;
this.selectedResearchers = [];
if(this.myComboBox){
this.myComboBox.clearSelection();
this.comboBoxOnChange();
}
this.location.replaceState("/admin/"+this.selectedLabo.name+"/");
this.location.replaceState("/admin/"+this.selectedLabo.name+"/");
}
selectAllResearchers(){
this.preSelected = null;
let modal = this.modalService.open(ValidModalContent);
modal.componentInstance.text = "Attention, cette action peut prendre plusieurs minutes";
modal.result.then((result) => { // ask if user really want to do this
if(result){ // if yes button is selected
this.selectedResearchers = [];
this.nbComputed = 0;
let i = 0;
this.preSelected = "Tous les membres";
for(let researcher of this.selectedLabo.researchers){
this.selectedResearchers.push(researcher);
i++;
this.preSelected = null;
let modal = this.modalService.open(ValidModalContent);
modal.componentInstance.text = "Attention, cette action peut prendre plusieurs minutes";
modal.result.then((result) => { // ask if user really want to do this
if(result){ // if yes button is selected
this.selectedResearchers = [];
this.nbComputed = 0;
let i = 0;
this.preSelected = "Tous les membres";
for(let researcher of this.selectedLabo.researchers){
this.selectedResearchers.push(researcher);
i++;
// if(i == 50){ // for debugging
// break;
// }
}
}
});
}
}
});
}
detailsComputed(event){
if(event != null){
//console.log("ResearcherList details : ", event, this.selectedResearchers);
this.nbComputed++;
let percent = Math.ceil((this.nbComputed/this.selectedResearchers.length)*100);
if(percent < 100)
this.title.setTitle("Spirhal - loading "+percent+"%");
else
this.title.setTitle("Spirhal");
}
}
sendMail(researcher){
let modal = this.modalService.open(ValidModalContent);
modal.componentInstance.text = "Envoyer un mail à : "+researcher.name.valName;
modal.result.then((result) => { // ask if user really want to do this
if(result){ // if yes button is selected
this.proxy.sendMail(researcher, this.norm);
}
});
}
sendMailAll(){
let modal = this.modalService.open(ValidModalContent);
let researchersWithoutMail = [];
for(let res of this.selectedResearchers){
if(!res.email){
researchersWithoutMail.push(res.name.valName);
}
}
modal.componentInstance.text = "Envoyer un mail à : "+(this.selectedResearchers.length - researchersWithoutMail.length)+" membres.";
if(researchersWithoutMail.length > 0){
modal.componentInstance.text += " Il y a "+researchersWithoutMail.length+" adresse(s) email manquante(s) : ";
for(let s of researchersWithoutMail){
modal.componentInstance.text += s+", ";
}
}
modal.result.then((result) => { // ask if user really want to do this
if(result){ // if yes button is selected
for(let researcher of this.selectedResearchers){
if(researcher.email)
this.proxy.sendMail(researcher, this.norm);
}
}
});
}
normChanged(){
this.normChanging = true;
let timeoutId = setTimeout(() => { // wait a bit cause the 'no publications' message is display during the initialization phase (what a hack!)
this.normChanging = false;
}, 500);
}
detailsComputed(event){
if(event != null){
//console.log("ResearcherList details : ", event, this.selectedResearchers);
this.nbComputed++;
let percent = Math.ceil((this.nbComputed/this.selectedResearchers.length)*100);
if(percent < 100)
this.title.setTitle("Spirhal - loading "+percent+"%");
else
this.title.setTitle("Spirhal");
}
}
sendMail(researcher){
let modal = this.modalService.open(ValidModalContent);
modal.componentInstance.text = "Envoyer un mail à : "+researcher.name.valName;
modal.result.then((result) => { // ask if user really want to do this
if(result){ // if yes button is selected
this.proxy.sendMail(researcher, this.norm);
}
});
}
sendMailAll(){
let modal = this.modalService.open(ValidModalContent);
let researchersWithoutMail = [];
for(let res of this.selectedResearchers){
if(!res.email){
researchersWithoutMail.push(res.name.valName);
}
}
modal.componentInstance.text = "Envoyer un mail à : "+(this.selectedResearchers.length - researchersWithoutMail.length)+" membres.";
if(researchersWithoutMail.length > 0){
modal.componentInstance.text += " Il y a "+researchersWithoutMail.length+" adresse(s) email manquante(s) : ";
for(let s of researchersWithoutMail){
modal.componentInstance.text += s+", ";
}
}
modal.result.then((result) => { // ask if user really want to do this
if(result){ // if yes button is selected
for(let researcher of this.selectedResearchers){
if(researcher.email)
this.proxy.sendMail(researcher, this.norm);
}
}
});
}
normChanged(){
this.normChanging = true;
let timeoutId = setTimeout(() => { // wait a bit cause the 'no publications' message is display during the initialization phase (what a hack!)
this.normChanging = false;
}, 500);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment