Skip to content

Commit e1b0518

Browse files
committed
Fix profile completion percentage fluctuation
Update the profile completion logic to calculate percentage based on a fixed list of fields rather than iterating over all API response keys. This prevents the percentage from fluctuating when the backend returns inconsistent metadata fields. Fixes #3278
1 parent d4ce4fa commit e1b0518

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

frontend/src/js/controllers/profileCtrl.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,29 @@
5353
var status = response.status;
5454
var result = response.data;
5555
if (status == 200) {
56-
for (var i in result) {
57-
if (result[i] === "" || result[i] === undefined || result[i] === null) {
58-
if (i === "linkedin_url" || i === "github_url" || i === "google_scholar_url") {
59-
result[i] = "";
60-
} else {
61-
result[i] = "";
62-
}
63-
vm.countLeft = vm.countLeft + 1;
56+
57+
var profileFields = ['first_name', 'last_name', 'affiliation', 'github_url', 'google_scholar_url', 'linkedin_url'];
58+
59+
// Reset counters to ensure stability
60+
vm.countLeft = 0;
61+
count = 0;
62+
63+
// Iterate only over the specific profile fields
64+
profileFields.forEach(function(field) {
65+
count++; // Total fields is always fixed (e.g., 6)
66+
67+
// Check if the field is empty/null/undefined
68+
if (!result[field] || result[field] === "") {
69+
result[field] = ""; // Ensure UI binds to empty string instead of null
70+
vm.countLeft++;
6471
}
65-
count = count + 1;
66-
}
67-
vm.compPerc = parseInt((vm.countLeft / count) * 100);
72+
});
73+
74+
vm.compPerc = parseInt(((count - vm.countLeft) / count) * 100);
6875

6976
vm.user = result;
7077
vm.userdetails = angular.copy(result);
71-
vm.user.complete = 100 - vm.compPerc;
72-
78+
vm.user.complete = vm.compPerc;
7379
}
7480
},
7581
onError: function(response) {

0 commit comments

Comments
 (0)