aboutsummaryrefslogtreecommitdiff
path: root/weed/admin/view/app/cluster_collections.templ
blob: 202058ca757c350058321e48d593283ed87bfc51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package app

import (
    "fmt"
    "github.com/seaweedfs/seaweedfs/weed/admin/dash"
)

templ ClusterCollections(data dash.ClusterCollectionsData) {
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">
            <i class="fas fa-layer-group me-2"></i>Cluster Collections
        </h1>
        <div class="btn-toolbar mb-2 mb-md-0">
            <div class="btn-group me-2">
                <button type="button" class="btn btn-sm btn-outline-primary" onclick="exportCollections()">
                    <i class="fas fa-download me-1"></i>Export
                </button>
                <button type="button" class="btn btn-sm btn-success" data-bs-toggle="modal" data-bs-target="#createCollectionModal">
                    <i class="fas fa-plus me-1"></i>Create Collection
                </button>
            </div>
        </div>
    </div>

    <div id="collections-content">
        <!-- Summary Cards -->
        <div class="row mb-4">
            <div class="col-xl-3 col-md-6 mb-4">
                <div class="card border-left-primary shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                                    Total Collections
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {fmt.Sprintf("%d", data.TotalCollections)}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-layer-group fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-xl-3 col-md-6 mb-4">
                <div class="card border-left-success shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                    Active Collections
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {fmt.Sprintf("%d", countActiveCollections(data.Collections))}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-check-circle fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-xl-3 col-md-6 mb-4">
                <div class="card border-left-info shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
                                    Total Volumes
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {fmt.Sprintf("%d", data.TotalVolumes)}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-database fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-xl-3 col-md-6 mb-4">
                <div class="card border-left-warning shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                                    Total Files
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {fmt.Sprintf("%d", data.TotalFiles)}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-file fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Second Row of Summary Cards -->
        <div class="row mb-4">
            <div class="col-xl-6 col-md-6 mb-4">
                <div class="card border-left-secondary shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-secondary text-uppercase mb-1">
                                    Total Storage Size
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {formatBytes(data.TotalSize)}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-hdd fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-xl-6 col-md-6 mb-4">
                <div class="card border-left-dark shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-dark text-uppercase mb-1">
                                    Data Centers
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {fmt.Sprintf("%d", countUniqueCollectionDataCenters(data.Collections))}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-building fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Collections Table -->
        <div class="card shadow mb-4">
            <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary">
                    <i class="fas fa-layer-group me-2"></i>Collection Details
                </h6>
            </div>
            <div class="card-body">
                if len(data.Collections) > 0 {
                    <div class="table-responsive">
                        <table class="table table-hover" id="collectionsTable">
                            <thead>
                                <tr>
                                    <th>Collection Name</th>
                                    <th>Data Center</th>
                                    <th>Replication</th>
                                    <th>Volumes</th>
                                    <th>Files</th>
                                    <th>Size</th>
                                    <th>Disk Types</th>
                                    <th>Status</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                for _, collection := range data.Collections {
                                    <tr>
                                        <td>
                                            <strong>{collection.Name}</strong>
                                        </td>
                                        <td>
                                            <span class="badge bg-light text-dark">{collection.DataCenter}</span>
                                        </td>
                                        <td>
                                            <span class="badge bg-info">{collection.Replication}</span>
                                        </td>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                <i class="fas fa-database me-2 text-muted"></i>
                                                {fmt.Sprintf("%d", collection.VolumeCount)}
                                            </div>
                                        </td>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                <i class="fas fa-file me-2 text-muted"></i>
                                                {fmt.Sprintf("%d", collection.FileCount)}
                                            </div>
                                        </td>
                                        <td>
                                            <div class="d-flex align-items-center">
                                                <i class="fas fa-hdd me-2 text-muted"></i>
                                                {formatBytes(collection.TotalSize)}
                                            </div>
                                        </td>
                                        <td>
                                            for i, diskType := range collection.DiskTypes {
                                                if i > 0 {
                                                    <span class="me-1"></span>
                                                }
                                                <span class={fmt.Sprintf("badge bg-%s me-1", getDiskTypeColor(diskType))}>{diskType}</span>
                                            }
                                            if len(collection.DiskTypes) == 0 {
                                                <span class="text-muted">Unknown</span>
                                            }
                                        </td>
                                        <td>
                                            <span class={fmt.Sprintf("badge bg-%s", getStatusColor(collection.Status))}>
                                                {collection.Status}
                                            </span>
                                        </td>
                                        <td>
                                            <div class="btn-group btn-group-sm">
                                                <button type="button" class="btn btn-outline-primary btn-sm" 
                                                        title="View Details">
                                                    <i class="fas fa-eye"></i>
                                                </button>
                                                <button type="button" class="btn btn-outline-secondary btn-sm" 
                                                        title="Edit">
                                                    <i class="fas fa-edit"></i>
                                                </button>
                                                <button type="button" class="btn btn-outline-danger btn-sm" 
                                                        title="Delete"
                                                        data-collection-name={collection.Name}
                                                        onclick="confirmDeleteCollection(this)">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                } else {
                    <div class="text-center py-5">
                        <i class="fas fa-layer-group fa-3x text-muted mb-3"></i>
                        <h5 class="text-muted">No Collections Found</h5>
                        <p class="text-muted">No collections are currently configured in the cluster.</p>
                        <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#createCollectionModal">
                            <i class="fas fa-plus me-2"></i>Create First Collection
                        </button>
                    </div>
                }
            </div>
        </div>

        <!-- Last Updated -->
        <div class="row">
            <div class="col-12">
                <small class="text-muted">
                    <i class="fas fa-clock me-1"></i>
                    Last updated: {data.LastUpdated.Format("2006-01-02 15:04:05")}
                </small>
            </div>
        </div>
    </div>

    <!-- Create Collection Modal -->
    <div class="modal fade" id="createCollectionModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">
                        <i class="fas fa-plus me-2"></i>Create New Collection
                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <form id="createCollectionForm">
                    <div class="modal-body">
                        <div class="mb-3">
                            <label for="collectionName" class="form-label">Collection Name</label>
                            <input type="text" class="form-control" id="collectionName" name="name" required>
                            <div class="form-text">Enter a unique name for the collection</div>
                        </div>
                        <div class="mb-3">
                            <label for="replication" class="form-label">Replication</label>
                            <select class="form-select" id="replication" name="replication" required>
                                <option value="000">000 - No replication</option>
                                <option value="001" selected>001 - Replicate once on same rack</option>
                                <option value="010">010 - Replicate once on different rack</option>
                                <option value="100">100 - Replicate once on different data center</option>
                                <option value="200">200 - Replicate twice on different data centers</option>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label for="ttl" class="form-label">TTL (Time To Live)</label>
                            <input type="text" class="form-control" id="ttl" name="ttl" placeholder="e.g., 1d, 7d, 30d">
                            <div class="form-text">Optional: Specify how long files should be kept</div>
                        </div>
                        <div class="mb-3">
                            <label for="diskType" class="form-label">Disk Type</label>
                            <select class="form-select" id="diskType" name="diskType">
                                <option value="hdd" selected>HDD</option>
                                <option value="ssd">SSD</option>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary">Create Collection</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Delete Confirmation Modal -->
    <div class="modal fade" id="deleteCollectionModal" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title text-danger">
                        <i class="fas fa-exclamation-triangle me-2"></i>Delete Collection
                    </h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <p>Are you sure you want to delete the collection <strong id="deleteCollectionName"></strong>?</p>
                    <div class="alert alert-warning">
                        <i class="fas fa-warning me-2"></i>
                        This action cannot be undone. All volumes in this collection will be affected.
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-danger" id="confirmDeleteCollection">Delete Collection</button>
                </div>
            </div>
        </div>
    </div>
}

func countActiveCollections(collections []dash.CollectionInfo) int {
    count := 0
    for _, collection := range collections {
        if collection.Status == "active" {
            count++
        }
    }
    return count
}

func countUniqueCollectionDataCenters(collections []dash.CollectionInfo) int {
    dcMap := make(map[string]bool)
    for _, collection := range collections {
        dcMap[collection.DataCenter] = true
    }
    return len(dcMap)
}

func getDiskTypeColor(diskType string) string {
    switch diskType {
    case "ssd":
        return "primary"
    case "hdd", "":
        return "secondary"
    default:
        return "info"
    }
}

func formatDiskTypes(diskTypes []string) string {
    if len(diskTypes) == 0 {
        return "Unknown"
    }
    if len(diskTypes) == 1 {
        return diskTypes[0]
    }
    // For multiple disk types, join with comma
    result := ""
    for i, diskType := range diskTypes {
        if i > 0 {
            result += ", "
        }
        result += diskType
    }
    return result
}