beanbagdb-components 0.2.0 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/app.js CHANGED
@@ -1,14 +1,58 @@
1
- const initPage = async (params) => {
2
- // 1. Check if "db" param exists, throw error if missing
1
+ /**
2
+ * This method can be used in local html apps for initialization based on the params provided in the url.
3
+ * Accepted params: db, doc
4
+ * Each has a specific format
5
+ *
6
+ * @param {*} params
7
+ * @returns
8
+ */
9
+
10
+ const initPage = async (page_name,params) => {
11
+
3
12
  const urlParams = new URLSearchParams(params || window.location.search);
4
- const dbParam = urlParams.get('db');
5
-
6
- if (!dbParam) {
7
- throw new Error('Required "db" parameter is missing from URL');
13
+ let dbParam = urlParams.get("db");
14
+ const docParam = urlParams.get("doc");
15
+
16
+ let parsedDocCriteria = null;
17
+ let dbName = null;
18
+ if (dbParam) {
19
+ dbName = dbParam;
20
+ } else if (docParam) {
21
+ /**
22
+ * the doc parameter has a fixed format db_name.identifier1.value1.identifier2.value2...
23
+ */
24
+ const parts = docParam.split(".");
25
+
26
+ if (parts.length < 3 || parts.length % 2 === 0) {
27
+ throw new Error(
28
+ 'Invalid "doc" parameter format. Expected: db_name.identifier1.value1.identifier2.value2...',
29
+ );
30
+ }
31
+
32
+ dbName = parts[0];
33
+ parsedDocCriteria = {}
34
+ // Parse identifier-value pairs
35
+ for (let i = 1; i < parts.length; i += 2) {
36
+ const identifier = parts[i];
37
+ const value = parts[i + 1];
38
+ parsedDocCriteria[identifier] = value;
39
+ }
40
+ } else {
41
+ throw new Error(
42
+ "No identifier params provided. Either specify db (database name) or doc (dbname.id1.val1) like test1._id.12345 or test1.link.12345 ",
43
+ );
44
+ }
45
+
46
+ // console.log(parsedDocCriteria)
47
+ // console.log(dbName)
48
+
49
+ // Now check if dbParam exists (either from URL or from doc)
50
+ if (!dbName) {
51
+ throw new Error("Required database name is not provided");
8
52
  }
9
53
 
10
54
  // 2. Get the bbdb-db-list array from localStorage
11
- const dbListJson = localStorage.getItem('bbdb-db-list');
55
+ const dbListJson = localStorage.getItem("bbdb-db-list");
12
56
  if (!dbListJson) {
13
57
  throw new Error('No databases found in localStorage "bbdb-db-list"');
14
58
  }
@@ -16,59 +60,72 @@ const initPage = async (params) => {
16
60
  const dbList = JSON.parse(dbListJson); // [{name: ""}, {}]
17
61
 
18
62
  // 3. Find matching db object by name
19
- const dbObj = dbList.find(db => db.name === dbParam);
20
-
63
+ const dbObj = dbList.find((db) => db.name === dbName);
21
64
  if (!dbObj) {
22
65
  throw new Error(`Database "${dbParam}" not found in bbdb-db-list`);
23
66
  }
24
67
 
25
- return dbObj;
68
+ let result = { dbObj, parsedDocCriteria }
69
+ if(page_name=="doc"){
70
+ //for the document page, if db is provided show search bar, if doc provided do not show the search bar
71
+ result["single_record"] = !(parsedDocCriteria==null)
72
+ result["new_record"] = parsedDocCriteria==null
73
+ }
74
+ return result;
26
75
  };
27
76
 
28
77
  const showMessage = (type, message) => {
29
- let messageEl = document.querySelector('#show-message');
30
-
31
- // Color mapping based on type
32
- const colors = {
33
- 'error': '#dc3545',
34
- 'success': '#28a745',
35
- 'warning': '#ffc107',
36
- 'info': '#17a2b8'
78
+ let messageEl = document.querySelector("#show-message");
79
+
80
+ // Bootstrap 5 alert type mapping
81
+ const alertTypes = {
82
+ error: "alert-danger",
83
+ success: "alert-success",
84
+ warning: "alert-warning",
85
+ info: "alert-info",
37
86
  };
38
-
39
- const color = colors[type] || '#6c757d';
40
-
87
+
88
+ const alertType = alertTypes[type] || "alert-secondary";
89
+
41
90
  if (messageEl) {
42
- // Replace existing content
43
- messageEl.innerHTML = `${message} <button onclick="this.parentElement.remove()">X</button>`;
91
+ // Update existing alert
92
+ messageEl.className = `alert ${alertType} alert-dismissible fade show position-fixed top-0 start-50 translate-middle-x`;
93
+ messageEl.innerHTML = `<strong>${message}</strong> <button type="button" class="btn-close" onclick="this.parentElement.remove()" aria-label="Close"></button>`;
44
94
  } else {
45
- // Create new div on top of body
46
- messageEl = document.createElement('div');
47
- messageEl.id = 'show-message';
48
- messageEl.innerHTML = `${message} <button onclick="this.parentElement.remove()">X</button>`;
49
- document.body.prepend(messageEl); // Adds dynamically on top of body
95
+ // Create new Bootstrap alert
96
+ messageEl = document.createElement("div");
97
+ messageEl.id = "show-message";
98
+ messageEl.className = `alert ${alertType} alert-dismissible fade show position-fixed top-0 start-50 translate-middle-x`;
99
+ messageEl.innerHTML = `<strong>${message}</strong> <button type="button" class="btn-close" onclick="this.parentElement.remove()" aria-label="Close"></button>`;
100
+ document.body.prepend(messageEl);
50
101
  }
51
-
52
- // Apply styling
102
+
103
+ // Position and size styling
53
104
  Object.assign(messageEl.style, {
54
- color: color,
55
- padding: '15px',
56
- margin: '1',
57
- boxShadow: `2px 10px 9px -5px rgba(0,0,0,0.2)`,
58
- background: '#f8f9fa',
59
- borderBottom: `4px solid ${color}`,
60
- //boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
61
- position: 'relative'
62
- });
63
-
64
- // Style the close button
65
- const closeBtn = messageEl.querySelector('button');
66
- Object.assign(closeBtn.style, {
67
- float: 'right',
68
- border: 'none',
69
- background: 'none',
70
- fontSize: '20px',
71
- cursor: 'pointer',
72
- fontWeight: 'bold'
105
+ zIndex: "9999",
106
+ width: "90%",
107
+ maxWidth: "500px",
108
+ marginTop: "20px",
73
109
  });
74
110
  };
111
+
112
+
113
+
114
+ const handle_bbdb_action = (action_data)=>{
115
+ //console.log(action_data)
116
+ let action = action_data.detail
117
+ //console.log(action)
118
+ if(!action.name){
119
+ showMessage("error","No actions name provided")
120
+ }
121
+ const all_actions = {
122
+ "message":()=>{
123
+ showMessage(action.type,action.message)
124
+ },
125
+ "message_link":()=>{
126
+ let message = `${action.message} Doc Link : <a href='doc.html?doc=${action.link}' target='_blank'>View</a>`
127
+ showMessage(action.type,message)
128
+ }
129
+ }
130
+ all_actions[action.name]()
131
+ }
@@ -0,0 +1,51 @@
1
+ .gutter {
2
+ background-color: #eee;
3
+
4
+ background-repeat: no-repeat;
5
+ background-position: 50%;
6
+ }
7
+
8
+ .gutter.gutter-vertical {
9
+ background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAFAQMAAABo7865AAAABlBMVEVHcEzMzMzyAv2sAAAAAXRSTlMAQObYZgAAABBJREFUeF5jOAMEEAIEEFwAn3kMwcB6I2AAAAAASUVORK5CYII=');
10
+ }
11
+
12
+ .gutter.gutter-horizontal {
13
+ background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAeCAYAAADkftS9AAAAIklEQVQoU2M4c+bMfxAGAgYYmwGrIIiDjrELjpo5aiZeMwF+yNnOs5KSvgAAAABJRU5ErkJggg==');
14
+ }
15
+
16
+
17
+ html, body {
18
+ height: 100vh;
19
+ margin: 0;
20
+ padding: 0;
21
+ /* overflow: hidden; */
22
+ }
23
+
24
+ #app {
25
+ height: 100vh;
26
+ padding-bottom: 0;
27
+ }
28
+
29
+
30
+
31
+ .tabulator {
32
+ height: 100% !important;
33
+ min-height: 400px;
34
+ }
35
+
36
+ .gutter {
37
+ background-color: #444;
38
+ cursor: col-resize;
39
+ }
40
+
41
+ .gutter.gutter-hover {
42
+ background-color: #666;
43
+ }
44
+
45
+ .navbar-brand{
46
+ font-size: 16px;
47
+ }
48
+
49
+ .accordion-header{
50
+ font-size: 12px;
51
+ }