Skip to content

Commit

Permalink
Beautify and multiline js codes in views (2600hz#6265)
Browse files Browse the repository at this point in the history
Adding (and ran) a script to make JavaScript codes in CouchDB view
files beautify and multi-line so make it more readable to
developers. Also makes keep tracking changes easy during PR reviews.

kz_datamgr:maybe_adapt_multiline/1 is updated to reverse multi-lined
views back to simple string for all view's functions (such as lists,
shows and of course views).
  • Loading branch information
icehess authored and jamesaimonetti committed Feb 4, 2020
1 parent 3016366 commit 3bfdec2
Show file tree
Hide file tree
Showing 140 changed files with 2,412 additions and 756 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
working_directory: ~/2600hz/kazoo
shell: /bin/bash --login
environment:
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
environment:
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ apis:
@$(ROOT)/scripts/format-json.py $(shell find applications core -wholename '*/api/*.json')
@ERL_LIBS=deps:core:applications $(ROOT)/scripts/generate-fs-headers-hrl.escript
@ERL_LIBS=deps:core:applications $(ROOT)/scripts/generate-kzd-builders.escript
## FIXME: copy-paste from fmt.mk fmt-views-all target
## adding that target to circleci steps for every app is painful
## also this formatting is better to be done before validate-js ci step to make sure
## the view is still in correct shape
@$(ROOT)/scripts/format-couchdb-views.py core/kazoo_apps/priv/couchdb/account
@$(ROOT)/scripts/format-couchdb-views.py $(shell find applications core -wholename '*/couchdb/views/*.json')

schemas:
@ERL_LIBS=deps:core:applications $(ROOT)/scripts/generate-schemas.escript
Expand Down
4 changes: 2 additions & 2 deletions applications/acdc/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
7 changes: 6 additions & 1 deletion applications/acdc/priv/couchdb/views/acdc.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
"language": "javascript",
"views": {
"accounts_listing": {
"map": "function(doc) { if (doc.pvt_type != 'acdc_activation' || doc.pvt_deleted) return; emit(doc.pvt_account_id, null); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'acdc_activation' || doc.pvt_deleted) return;",
" emit(doc.pvt_account_id, null);",
"}"
]
}
}
}
21 changes: 18 additions & 3 deletions applications/acdc/priv/couchdb/views/agent_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,28 @@
"language": "javascript",
"views": {
"most_recent_by_agent": {
"map": "function(doc) { if ( doc.pvt_type != 'status_stat' ) return; emit([doc.agent_id, doc.timestamp], null); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'status_stat') return;",
" emit([doc.agent_id, doc.timestamp], null);",
"}"
]
},
"most_recent_by_timestamp": {
"map": "function(doc) { if ( doc.pvt_type != 'status_stat' ) return; emit([doc.timestamp, doc.agent_id], null); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'status_stat') return;",
" emit([doc.timestamp, doc.agent_id], null);",
"}"
]
},
"status_log": {
"map": "function(doc) { if ( doc.pvt_type != 'status_stat' ) return; emit([doc.agent_id, doc.timestamp], doc.status); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'status_stat') return;",
" emit([doc.agent_id, doc.timestamp], doc.status);",
"}"
]
}
}
}
11 changes: 10 additions & 1 deletion applications/acdc/priv/couchdb/views/agents.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
"language": "javascript",
"views": {
"crossbar_listing": {
"map": "function(doc) { if (doc.pvt_type !== 'user' || typeof doc.queues !== 'object' || doc.pvt_deleted) return; emit(doc._id, {'first_name': doc.first_name, 'last_name': doc.last_name, 'queues':doc.queues}); }"
"map": [
"function(doc) {",
" if (doc.pvt_type !== 'user' || typeof doc.queues !== 'object' || doc.pvt_deleted) return;",
" emit(doc._id, {",
" 'first_name': doc.first_name,",
" 'last_name': doc.last_name,",
" 'queues': doc.queues",
" });",
"}"
]
}
}
}
34 changes: 16 additions & 18 deletions applications/acdc/priv/couchdb/views/call_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,28 @@
"call_log": {
"map": [
"function(doc) {",
" if ( doc.pvt_type != 'call_stat' )",
" return;",
" emit([doc.queue_id, doc.entered_timestamp], null);",
" if (doc.pvt_type != 'call_stat') return;",
" emit([doc.queue_id, doc.entered_timestamp], null);",
"}"
]
},
"crossbar_listing": {
"map": [
"function(doc) {",
" if ( doc.pvt_type != 'call_stat' )",
" return;",
" emit(doc.entered_timestamp, {",
" id: doc._id,",
" entered_timestamp: doc.entered_timestamp,",
" handled_timestamp: doc.handled_timestamp,",
" caller_id_number: doc.caller_id_number,",
" caller_id_name: doc.caller_id_name,",
" entered_position: doc.entered_position,",
" status: doc.status,",
" agent_id: doc.agent_id,",
" wait_time: doc.wait_time,",
" talk_time: doc.talk_time,",
" queue_id: doc.queue_id",
" });",
" if (doc.pvt_type != 'call_stat') return;",
" emit(doc.entered_timestamp, {",
" id: doc._id,",
" entered_timestamp: doc.entered_timestamp,",
" handled_timestamp: doc.handled_timestamp,",
" caller_id_number: doc.caller_id_number,",
" caller_id_name: doc.caller_id_name,",
" entered_position: doc.entered_position,",
" status: doc.status,",
" agent_id: doc.agent_id,",
" wait_time: doc.wait_time,",
" talk_time: doc.talk_time,",
" queue_id: doc.queue_id",
" });",
"}"
]
}
Expand Down
20 changes: 18 additions & 2 deletions applications/acdc/priv/couchdb/views/queues.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,27 @@
"language": "javascript",
"views": {
"agents_listing": {
"map": "function(doc) { if (doc.pvt_type !== 'user' || doc.pvt_deleted || typeof doc.queues !== 'object' ) return; for ( i in doc.queues ) { emit(doc.queues[i], doc._id); }}",
"map": [
"function(doc) {",
" if (doc.pvt_type !== 'user' || doc.pvt_deleted || typeof doc.queues !== 'object') return;",
" for (i in doc.queues) {",
" emit(doc.queues[i], doc._id);",
" }",
"}"
],
"reduce": "_count"
},
"crossbar_listing": {
"map": "function(doc) { if (doc.pvt_type != 'queue' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'name': doc.name, 'strategy': doc.strategy}); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'queue' || doc.pvt_deleted) return;",
" emit(doc._id, {",
" 'id': doc._id,",
" 'name': doc.name,",
" 'strategy': doc.strategy",
" });",
"}"
]
}
}
}
4 changes: 2 additions & 2 deletions applications/ananke/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
4 changes: 2 additions & 2 deletions applications/blackhole/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
4 changes: 2 additions & 2 deletions applications/braintree/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
4 changes: 2 additions & 2 deletions applications/call_inspector/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
4 changes: 2 additions & 2 deletions applications/callflow/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
4 changes: 2 additions & 2 deletions applications/camper/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
4 changes: 2 additions & 2 deletions applications/cccp/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
40 changes: 37 additions & 3 deletions applications/cccp/priv/couchdb/views/cccps.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,47 @@
"language": "javascript",
"views": {
"cid_listing": {
"map": "function(doc) { if (doc.pvt_type != 'cccp' || !doc.active || !doc.cid || doc.pvt_deleted) return; emit(doc.cid, {'id': doc._id, 'account_id': doc.pvt_account_id, 'user_id':doc.user_id, 'retain_cid':doc.retain_cid}); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'cccp' || !doc.active || !doc.cid || doc.pvt_deleted) return;",
" emit(doc.cid, {",
" 'id': doc._id,",
" 'account_id': doc.pvt_account_id,",
" 'user_id': doc.user_id,",
" 'retain_cid': doc.retain_cid",
" });",
"}"
]
},
"crossbar_listing": {
"map": "function(doc) { if (doc.pvt_type != 'cccp' || doc.pvt_deleted) return; emit(doc._id, {'id': doc._id, 'account_id': doc.pvt_account_id, 'active':doc.active, 'user_id':doc.user_id, 'cid':doc.cid, 'pin':doc.pin, 'retain_cid':doc.retain_cid, 'comment':doc.comment}); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'cccp' || doc.pvt_deleted) return;",
" emit(doc._id, {",
" 'id': doc._id,",
" 'account_id': doc.pvt_account_id,",
" 'active': doc.active,",
" 'user_id': doc.user_id,",
" 'cid': doc.cid,",
" 'pin': doc.pin,",
" 'retain_cid': doc.retain_cid,",
" 'comment': doc.comment",
" });",
"}"
]
},
"pin_listing": {
"map": "function(doc) { if (doc.pvt_type != 'cccp' || !doc.active || !doc.pin || doc.pvt_deleted) return; emit(doc.pin, {'id': doc._id, 'account_id': doc.pvt_account_id, 'user_id':doc.user_id, 'retain_cid':doc.retain_cid}); }"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'cccp' || !doc.active || !doc.pin || doc.pvt_deleted) return;",
" emit(doc.pin, {",
" 'id': doc._id,",
" 'account_id': doc.pvt_account_id,",
" 'user_id': doc.user_id,",
" 'retain_cid': doc.retain_cid",
" });",
"}"
]
}
}
}
4 changes: 2 additions & 2 deletions applications/cdr/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflows:

defaults: &defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
shell: /bin/bash --login
working_directory: ~/2600hz/the_app
environment:
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
release:
<<: *defaults
docker:
- image: offical2600hz/circleci:21.3.8.8
- image: offical2600hz/circleci:21.3.8.12
- image: couchdb:2.3.1
- image: 2600hz/rabbitmq
steps:
Expand Down
Loading

0 comments on commit 3bfdec2

Please sign in to comment.