Make all JS functions and variables camelCase
According to conventions.
This commit is contained in:
parent
3939470679
commit
8a38274280
|
@ -24,22 +24,22 @@ SortFilterProxyModel {
|
||||||
return model.setProperty(index, prop, value)
|
return model.setProperty(index, prop, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function extend(new_items) {
|
function extend(newItems) {
|
||||||
for (var i = 0; i < new_items.length; i++) {
|
for (var i = 0; i < newItems.length; i++) {
|
||||||
model.append(new_items[i])
|
model.append(newItems[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIndices(where_roles_are, max_results=null, max_tries=null) {
|
function getIndices(whereRolesAre, maxResults=null, maxTries=null) {
|
||||||
// max_results, max_tries: null or int
|
// maxResults, maxTries: null or int
|
||||||
var results = []
|
var results = []
|
||||||
|
|
||||||
for (var i = 0; i < model.count; i++) {
|
for (var i = 0; i < model.count; i++) {
|
||||||
var item = model.get(i)
|
var item = model.get(i)
|
||||||
var include = true
|
var include = true
|
||||||
|
|
||||||
for (var role in where_roles_are) {
|
for (var role in whereRolesAre) {
|
||||||
if (item[role] != where_roles_are[role]) {
|
if (item[role] != whereRolesAre[role]) {
|
||||||
include = false
|
include = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -47,20 +47,20 @@ SortFilterProxyModel {
|
||||||
|
|
||||||
if (include) {
|
if (include) {
|
||||||
results.push(i)
|
results.push(i)
|
||||||
if (max_results && results.length >= max_results) {
|
if (maxResults && results.length >= maxResults) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (max_tries && i >= max_tries) {
|
if (maxTries && i >= maxTries) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWhere(roles_are, max_results=null, max_tries=null) {
|
function getWhere(rolesAre, maxResults=null, maxTries=null) {
|
||||||
var indices = getIndices(roles_are, max_results, max_tries)
|
var indices = getIndices(rolesAre, maxResults, maxTries)
|
||||||
var items = []
|
var items = []
|
||||||
|
|
||||||
for (var i = 0; i < indices.length; i++) {
|
for (var i = 0; i < indices.length; i++) {
|
||||||
|
@ -69,36 +69,36 @@ SortFilterProxyModel {
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
function forEachWhere(roles_are, func, max_results=null, max_tries=null) {
|
function forEachWhere(rolesAre, func, maxResults=null, maxTries=null) {
|
||||||
var items = getWhere(roles_are, max_results, max_tries)
|
var items = getWhere(rolesAre, maxResults, maxTries)
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
func(items[i])
|
func(items[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function upsert(
|
function upsert(
|
||||||
where_roles_are, new_item, update_if_exist=true, max_tries=null
|
whereRolesAre, newItem, updateIfExist=true, maxTries=null
|
||||||
) {
|
) {
|
||||||
var indices = getIndices(where_roles_are, 1, max_tries)
|
var indices = getIndices(whereRolesAre, 1, maxTries)
|
||||||
|
|
||||||
if (indices.length == 0) {
|
if (indices.length == 0) {
|
||||||
model.append(new_item)
|
model.append(newItem)
|
||||||
return model.get(model.count)
|
return model.get(model.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
var existing = model.get(indices[0])
|
var existing = model.get(indices[0])
|
||||||
if (! update_if_exist) { return existing }
|
if (! updateIfExist) { return existing }
|
||||||
|
|
||||||
// Really update only if existing and new item have a difference
|
// Really update only if existing and new item have a difference
|
||||||
for (var role in existing) {
|
for (var role in existing) {
|
||||||
if (Boolean(existing[role].getTime)) {
|
if (Boolean(existing[role].getTime)) {
|
||||||
if (existing[role].getTime() != new_item[role].getTime()) {
|
if (existing[role].getTime() != newItem[role].getTime()) {
|
||||||
model.set(indices[0], new_item)
|
model.set(indices[0], newItem)
|
||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (existing[role] != new_item[role]) {
|
if (existing[role] != newItem[role]) {
|
||||||
model.set(indices[0], new_item)
|
model.set(indices[0], newItem)
|
||||||
return existing
|
return existing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,8 @@ SortFilterProxyModel {
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
function popWhere(roles_are, max_results=null, max_tries=null) {
|
function popWhere(rolesAre, maxResults=null, maxTries=null) {
|
||||||
var indices = getIndices(roles_are, max_results, max_tries)
|
var indices = getIndices(rolesAre, maxResults, maxTries)
|
||||||
var items = []
|
var items = []
|
||||||
|
|
||||||
for (var i = 0; i < indices.length; i++) {
|
for (var i = 0; i < indices.length; i++) {
|
||||||
|
@ -124,11 +124,11 @@ SortFilterProxyModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toObject(item_list=sortFilteredModel) {
|
function toObject(itemList=sortFilteredModel) {
|
||||||
var obj_list = []
|
var objList = []
|
||||||
|
|
||||||
for (var i = 0; i < item_list.count; i++) {
|
for (var i = 0; i < itemList.count; i++) {
|
||||||
var item = item_list.get(i)
|
var item = itemList.get(i)
|
||||||
var obj = JSON.parse(JSON.stringify(item))
|
var obj = JSON.parse(JSON.stringify(item))
|
||||||
|
|
||||||
for (var role in obj) {
|
for (var role in obj) {
|
||||||
|
@ -136,9 +136,9 @@ SortFilterProxyModel {
|
||||||
obj[role] = toObject(item[role])
|
obj[role] = toObject(item[role])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj_list.push(obj)
|
objList.push(obj)
|
||||||
}
|
}
|
||||||
return obj_list
|
return objList
|
||||||
}
|
}
|
||||||
|
|
||||||
function toJson() {
|
function toJson() {
|
||||||
|
|
|
@ -49,7 +49,7 @@ HRectangle {
|
||||||
eventList.canLoad = false
|
eventList.canLoad = false
|
||||||
py.callClientCoro(
|
py.callClientCoro(
|
||||||
chatPage.userId, "load_past_events", [chatPage.roomId],
|
chatPage.userId, "load_past_events", [chatPage.roomId],
|
||||||
more_to_load => { eventList.canLoad = more_to_load }
|
moreToLoad => { eventList.canLoad = moreToLoad }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@ import SortFilterProxyModel 0.2
|
||||||
import "../Base"
|
import "../Base"
|
||||||
|
|
||||||
HListModel {
|
HListModel {
|
||||||
function lastEventOf(room_id) {
|
function lastEventOf(roomId) {
|
||||||
// Return an event item or undefined if none found
|
// Return an event item or undefined if none found
|
||||||
|
|
||||||
for (var i = 0; i < count; i++) {
|
for (var i = 0; i < count; i++) {
|
||||||
var item = get(i) // TODO: standardize
|
var item = get(i) // TODO: standardize
|
||||||
if (item.roomId == room_id) { return item }
|
if (item.roomId == roomId) { return item }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ Item {
|
||||||
button.loading = true
|
button.loading = true
|
||||||
var args = [idField.text, passwordField.text]
|
var args = [idField.text, passwordField.text]
|
||||||
|
|
||||||
py.callCoro("login_client", args, user_id => {
|
py.callCoro("login_client", args, userId => {
|
||||||
pageStack.showPage("RememberAccount", {loginWith, user_id})
|
pageStack.showPage("RememberAccount", {loginWith, userId})
|
||||||
button.loading = false
|
button.loading = false
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
|
@ -26,11 +26,11 @@ Python {
|
||||||
call("APP.call_backend_coro", [name, uuid, args])
|
call("APP.call_backend_coro", [name, uuid, args])
|
||||||
}
|
}
|
||||||
|
|
||||||
function callClientCoro(account_id, name, args=[], callback=null) {
|
function callClientCoro(accountId, name, args=[], callback=null) {
|
||||||
var uuid = Math.random() + "." + name
|
var uuid = Math.random() + "." + name
|
||||||
|
|
||||||
pendingCoroutines[uuid] = callback || function() {}
|
pendingCoroutines[uuid] = callback || function() {}
|
||||||
call("APP.call_client_coro", [account_id, name, uuid, args])
|
call("APP.call_client_coro", [accountId, name, uuid, args])
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
|
|
@ -15,14 +15,14 @@ function hsla(hue, saturation, lightness, alpha=1.0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function arrayToModelItem(keys_name, array) {
|
function arrayToModelItem(keysName, array) {
|
||||||
// Convert an array to an object suitable to be in a model, example:
|
// Convert an array to an object suitable to be in a model, example:
|
||||||
// [1, 2, 3] → [{keys_name: 1}, {keys_name: 2}, {keys_name: 3}]
|
// [1, 2, 3] → [{keysName: 1}, {keysName: 2}, {keysName: 3}]
|
||||||
var items = []
|
var items = []
|
||||||
|
|
||||||
for (var i = 0; i < array.length; i++) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
var obj = {}
|
var obj = {}
|
||||||
obj[keys_name] = array[i]
|
obj[keysName] = array[i]
|
||||||
items.push(obj)
|
items.push(obj)
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
|
@ -59,10 +59,10 @@ function nameColor(name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function coloredNameHtml(name, user_id, display_text=null) {
|
function coloredNameHtml(name, userId, displayText=null) {
|
||||||
// substring: remove leading @
|
// substring: remove leading @
|
||||||
return "<font color='" + nameColor(name || alt_id.substring(1)) + "'>" +
|
return "<font color='" + nameColor(name || userId.substring(1)) + "'>" +
|
||||||
escapeHtml(display_text || name || alt_id) +
|
escapeHtml(displayText || name || userId) +
|
||||||
"</font>"
|
"</font>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user