+ // Add vname and user names:
+ decorate: function(problems, callback) {
+ if (this.st.variants.length > 0)
+ problems.forEach(p => this.setVname(p));
+ // Retrieve all problems' authors' names
+ let names = {};
+ problems.forEach(p => {
+ if (p.uid != this.st.user.id) names[p.uid] = "";
+ else p.uname = this.st.user.name;
+ });
+ if (Object.keys(names).length > 0) {
+ ajax(
+ "/users",
+ "GET",
+ {
+ data: { ids: Object.keys(names).join(",") },
+ success: (res2) => {
+ res2.users.forEach(u => {
+ names[u.id] = u.name;
+ });
+ problems.forEach(p => {
+ if (!p.uname)
+ p.uname = names[p.uid];
+ });
+ if (!!callback) callback();
+ }
+ }
+ );
+ } else if (!!callback) callback();
+ },
+ firstChars: function(text) {
+ let preparedText = text
+ // Replace line jumps and <br> by spaces
+ .replace(/\n/g, " ")
+ .replace(/<br\/?>/g, " ")
+ .replace(/<[^>]+>/g, "") //remove remaining HTML tags
+ .replace(/[ ]+/g, " ") //remove series of spaces by only one
+ .trim();
+ const maxLength = 32; //arbitrary...
+ if (preparedText.length > maxLength)
+ return preparedText.substr(0, 32) + "...";
+ return preparedText;
+ },