File size: 18,664 Bytes
a76d7af
582da9b
 
 
a76d7af
 
91b4b0a
8555b30
91b4b0a
8555b30
 
 
 
91b4b0a
a76d7af
 
91b4b0a
8555b30
 
91b4b0a
53fa589
 
 
 
 
d1d3947
53fa589
8555b30
 
 
 
a76d7af
 
91b4b0a
8555b30
91b4b0a
a76d7af
 
 
 
 
 
700339d
 
 
 
 
 
a76d7af
 
582da9b
 
 
a76d7af
91b4b0a
a76d7af
8555b30
91b4b0a
8555b30
 
 
 
a76d7af
 
 
582da9b
 
 
a76d7af
91b4b0a
a76d7af
8555b30
91b4b0a
8555b30
 
 
 
a76d7af
 
91b4b0a
582da9b
 
 
91b4b0a
 
 
8555b30
91b4b0a
8555b30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91b4b0a
 
53fa589
 
 
 
 
8555b30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91b4b0a
d1d3947
 
 
 
 
 
 
 
fbd466c
 
91b4b0a
 
 
 
 
 
 
700339d
 
d1d3947
 
 
700339d
d1d3947
 
 
91b4b0a
 
 
 
 
99781f6
91b4b0a
 
 
 
d1d3947
de9b9bc
 
91b4b0a
e92d70f
91b4b0a
 
 
 
 
 
 
 
 
 
a76d7af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0ad761
a76d7af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d0ad761
a76d7af
 
 
 
 
 
de9b9bc
 
a76d7af
de9b9bc
a76d7af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cec4e75
a76d7af
 
d0ad761
a76d7af
 
 
 
cec4e75
a76d7af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1d3947
91b4b0a
 
 
 
700339d
 
91b4b0a
 
 
 
 
 
 
 
 
 
 
9626424
0c56bcf
91b4b0a
 
d1d3947
 
 
 
 
 
 
 
700339d
 
91b4b0a
700339d
 
d1d3947
 
 
 
91b4b0a
700339d
 
 
 
 
 
 
 
 
53fa589
91b4b0a
 
 
700339d
e92d70f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700339d
e92d70f
 
 
 
 
 
 
 
 
700339d
e92d70f
 
 
 
 
 
 
 
 
 
700339d
e92d70f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
700339d
e92d70f
 
 
700339d
a76d7af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
de9b9bc
 
a76d7af
 
 
 
 
 
 
 
 
 
 
 
 
 
91b4b0a
 
 
 
 
 
8555b30
 
 
 
 
 
91b4b0a
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
// DOM elements
const dynamicDesc = document.getElementById("dynamicDesc");
const dynamicTitle = document.getElementById("dynamicTitle");

const singleModeBtn = document.getElementById('single-mode-btn');
const batchModeBtn = document.getElementById('batch-mode-btn');
const keywordModeBtn = document.getElementById("keyword-mode-btn");
const expModeBtn = document.getElementById("exp-mode-btn");

const singleInputField = document.querySelector('.single-input');
const batchInputField = document.querySelector('.batch-input');
const keywordInputField = document.querySelector(".keyword-input");
const expKeywordInputField = document.querySelector(".experimental-input");

const docIdInput = document.getElementById('doc-id');
const batchIdsInput = document.getElementById('batch-ids');
const keywordInput = document.getElementById("keywords");
const expKeywordInput = document.getElementById("exp-keywords")
const thresholdInput = document.getElementById("threshold");

const releaseFilter = document.querySelector("input[name=release]")
const modeFilter = document.querySelector("select[name=mode]")
const specTypeFilter = document.querySelector("select[name=spec_type]")
const workingGroupFilter = document.querySelector("select[name=working_group]")
const caseSensitiveFilter = document.querySelector("input[name=case_sensitive]")
const searchMode = document.querySelector("select[name=search_mode]")

const releaseFilter2 = document.querySelector("input[name=release2]")
const specTypeFilter2 = document.querySelector("select[name=spec_type2]")
const workingGroupFilter2 = document.querySelector("select[name=working_group2]")

const searchBtn = document.getElementById('search-btn');
const batchSearchBtn = document.getElementById('batch-search-btn');
const keywordSearchBtn = document.getElementById("keyword-search-btn");
const expKeywordSearchBtn = document.getElementById("exp-search-btn");

const loader = document.getElementById('loader');
const resultsContainer = document.getElementById('results-container');
const resultsList = document.getElementById('results-list');
const resultsStats = document.getElementById('results-stats');
const errorMessage = document.getElementById('error-message');

const sectionPopup = document.getElementById('sectionPopup');
const popupTitle = document.getElementById('popupTitle');
const popupTextareas = document.getElementById('popupTextareas');
const copyAllBtn = document.getElementById('copyAllBtn');
const closePopupBtn = document.querySelector('.close-popup');

// Search mode toggle
singleModeBtn.addEventListener('click', () => {
    dynamicTitle.textContent = "Find 3GPP Documents";
    dynamicDesc.textContent = "Enter a TSG document ID / specification ID (e.g., S1-123456, C2-987654 or 31.102) to locate the document in the 3GPP FTP server.";

    singleModeBtn.classList.add('active');
    keywordModeBtn.classList.remove("active");
    batchModeBtn.classList.remove('active');
    expModeBtn.classList.remove('active');

    singleInputField.style.display = 'block';
    batchInputField.style.display = 'none';
    keywordInputField.style.display = "none";
    expKeywordInputField.style.display = "none";
});

batchModeBtn.addEventListener('click', () => {
    dynamicTitle.textContent = "Find multiple 3GPP Documents";
    dynamicDesc.textContent = "Enter a list of TSG document ID / specification ID (e.g., S1-123456, C2-987654 or 31.102) to locate all of the specified documents in the 3GPP FTP server.";

    batchModeBtn.classList.add('active');
    keywordModeBtn.classList.remove("active");
    singleModeBtn.classList.remove('active');
    expModeBtn.classList.remove('active');

    batchInputField.style.display = 'block';
    keywordInputField.style.display = "none";
    singleInputField.style.display = 'none';
    expKeywordInputField.style.display = "none";
});

keywordModeBtn.addEventListener('click', () => {
    dynamicTitle.textContent = "Search 3GPP specifications";
    dynamicDesc.textContent = "With keywords and filters, find all of 3GPP's specifications that matches your needs (with keywords, specification number, release or even working group (C1, S5, SP, CP: always the first letter of the group followed by the workgroup number)";

    keywordModeBtn.classList.add("active");
    singleModeBtn.classList.remove('active');
    batchModeBtn.classList.remove("active");
    expModeBtn.classList.remove('active');

    singleInputField.style.display = "none";
    batchInputField.style.display = "none";
    expKeywordInputField.style.display = "none";
    keywordInputField.style.display = "block";
})

expModeBtn.addEventListener('click', () => {
    dynamicTitle.textContent = "[EXPERIMENTAL] Search 3GPP specifications";
    dynamicDesc.textContent = "With keywords and filters, find all of 3GPP's specifications that matches your needs (with keywords, specification number, release or even working group (C1, S5, SP, CP: always the first letter of the group followed by the workgroup number)";

    keywordModeBtn.classList.remove("active");
    singleModeBtn.classList.remove('active');
    batchModeBtn.classList.remove("active");
    expModeBtn.classList.add('active');

    singleInputField.style.display = "none";
    batchInputField.style.display = "none";
    expKeywordInputField.style.display = "block";
    keywordInputField.style.display = "none";
})

document.getElementById('toggleFilters').onclick = function() {
  var target = document.getElementById('filtersForm');
  target.style.display = (target.style.display === 'none' || target.style.display === '') ? 'flex' : 'none';
};

document.getElementById('toggleFilters2').onclick = function() {
  var target = document.getElementById('filtersForm2');
  target.style.display = (target.style.display === 'none' || target.style.display === '') ? 'flex' : 'none';
};

expKeywordSearchBtn.addEventListener("click", async ()=>{
    let keywords = expKeywordInput.value.trim();
    let release = releaseFilter2.value.trim();
    let wg = workingGroupFilter2.value.trim();
    let specType = specTypeFilter2.value.trim();
    let threshold = thresholdInput.value.trim();

    if (!keywords){
        showError("Please enter at least one keyword");
        return;
    }

    showLoader();
    hideError();

    try{
        let body = {
            keywords,
            threshold
        };
        if (release != ""){body["release"] = release}
        if (wg != ""){body["working_group"] = wg}
        if (specType != ""){body["spec_type"] = specType}
        const response = await fetch("/search-spec/experimental", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(body)
        });

        const data = await response.json();
        if (response.ok){
            displayKeywordResults(data, "");
        } else if (response.status == 404) {
            showError('No specification has been found');
        } else {
            showError(`Error processing keyword request: ${data.detail}`)
        }
    } catch (error) {
        showError('Error connecting to the server. Please check if the API is running.');
        console.error('Error:', error);
    } finally {
        hideLoader();
    }
})

keywordSearchBtn.addEventListener("click", async ()=>{
    let keywords = keywordInput.value.trim();
    let release = releaseFilter.value;
    let wg = workingGroupFilter.value;
    let specType = specTypeFilter.value;
    let search = searchMode.value;
    let checked = caseSensitiveFilter.checked;
    let mode = modeFilter.value;

    if (!keywords && searchMode == "deep") {
        showError("Please enter at least one keyword in deep search mode");
        return;
    }

    showLoader();
    hideError();

    try{
        let body = {
            keywords,
            "search_mode": search,
            "case_sensitive": checked,
            "mode": mode
        };
        if (release != ""){body.release = release}
        if (wg != ""){body["working_group"] = wg}
        if (specType != ""){body["spec_type"] = specType}
        const response = await fetch("/search-spec", {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(body)
        });

        const data = await response.json();
        if (response.ok){
            displayKeywordResults(data, search);
        } else if (response.status == 404) {
            showError('No specification has been found');
        } else {
            showError(`Error processing keyword request: ${data.detail}`)
        }
    } catch (error) {
        showError('Error connecting to the server. Please check if the API is running.');
        console.error('Error:', error);
    } finally {
        hideLoader();
    }
})


// Single document search
searchBtn.addEventListener('click', async () => {
    const docId = docIdInput.value.trim();
    if (!docId) {
        showError('Please enter a document ID');
        return;
    }

    showLoader();
    hideError();
    
    try {
        const response = await fetch(`/find`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ doc_id: docId, release: null })
        });

        const data = await response.json();
        
        if (response.ok) {
            displaySingleResult(data);
        } else {
            displaySingleNotFound(docId, data.detail);
        }
    } catch (error) {
        showError('Error connecting to the server. Please check if the API is running.');
        console.error('Error:', error);
    } finally {
        hideLoader();
    }
});

// Batch document search
batchSearchBtn.addEventListener('click', async () => {
    const batchText = batchIdsInput.value.trim();
    if (!batchText) {
        showError('Please enter at least one document ID');
        return;
    }

    const docIds = batchText.split('\n')
        .map(id => id.trim())
        .filter(id => id !== '');

    if (docIds.length === 0) {
        showError('Please enter at least one valid document ID');
        return;
    }

    showLoader();
    hideError();
    
    try {
        const response = await fetch(`/batch`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ doc_ids: docIds })
        });

        const data = await response.json();
        
        if (response.ok) {
            displayBatchResults(data);
        } else if (response.status == 404) {
            showError('No document has been found');
        } else {
            showError('Error processing batch request')
        }
    } catch (error) {
        showError('Error connecting to the server. Please check if the API is running.');
        console.error('Error:', error);
    } finally {
        hideLoader();
    }
});

// Display single result
function displaySingleResult(data) {
    resultsList.innerHTML = '';
    
    const resultItem = document.createElement('div');
    resultItem.className = 'result-item';
    let scopeItem = data.scope ? `<p>Scope : ${data.scope}</p>` : ""
    resultItem.innerHTML = `
        <div class="result-header">
            <div class="result-id">${data.doc_id}</div>
            <div class="result-status status-found">Found</div>
        </div>
        <div class="result-url">
            <a href="${data.url}" target="_blank">${data.url}</a>
            ${scopeItem}
        </div>
    `;
    
    resultsList.appendChild(resultItem);
    resultsStats.textContent = `Found in ${data.search_time.toFixed(2)} seconds`;
    resultsContainer.style.display = 'block';
}

// Display single not found result
function displaySingleNotFound(docId, message) {
    resultsList.innerHTML = '';
    
    const resultItem = document.createElement('div');
    resultItem.className = 'result-item';
    resultItem.innerHTML = `
        <div class="result-header">
            <div class="result-id">${docId}</div>
            <div class="result-status status-not-found">Not Found</div>
        </div>
        <div>${message}</div>
    `;
    
    resultsList.appendChild(resultItem);
    resultsStats.textContent = 'Document not found';
    resultsContainer.style.display = 'block';
}

function displayKeywordResults(data, mode) {
    resultsList.innerHTML = '';
    
    data.results.forEach(spec => {
        const resultItem = document.createElement("div");
        resultItem.className = "result-item";
        
        resultItem.innerHTML = `
            <div class="result-header">
                <div class="result-id">${spec.id}</div>
                <div class="result-status status-found">Found</div>
            </div>
            <div class="result-url">
                <p>Title: ${spec.title}</p>
                <p>Type: ${spec.type}</p>
                <p>Release: ${spec.release}</p>
                <p>Version: ${spec.version}</p>
                <p>WG: ${spec.working_group}</p>
                <p>URL: <a target="_blank" href="${spec.url}">${spec.url}</a></p>
                <p>Scope: ${spec.scope}</p>
            </div>
        `;

        if(mode == "deep"){
            resultItem.innerHTML += `
                <div class="result-actions">
                    <button class="get-section-btn btn" data-spec-id="${spec.id}">Get section</button>
                </div>
            `
        }
        
        // Ajouter le bouton au DOM
        resultsList.appendChild(resultItem);
        
        // Récupérer le bouton nouvellement créé
        if(mode == "deep"){
            const button1 = resultItem.querySelector('.get-section-btn');
            button1._sections = spec.contains;
        }
    });

    document.querySelectorAll('.get-section-btn').forEach(button => {
      button.addEventListener('click', function() {
        let specId = this.getAttribute("data-spec-id");
        let sections = this._sections;
        openSectionPopup(specId, sections);
      });
    });

    resultsStats.textContent = `Found ${data.results.length} in ${data.search_time.toFixed(2)} seconds`
    resultsContainer.style.display = 'block';
}

function openSectionPopup(specId, sections) {
    const newTab = window.open('', '_blank');
    let htmlContent = 
    `
        <!DOCTYPE html>
        <html lang="fr">
        <head>
          <meta charset="UTF-8">
          <title>Sections of specification number ${specId}</title>
          <link rel="stylesheet" href="/static/style.css">
          <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap">
        </head>
        <body>
            <div class="popup-header">
                <h2 id="popupTitle">Sections of specification number ${specId}</h2>
            </div>
            <div id="popupTextareas" class="popup-textareas">
    `;

    Object.entries(sections).forEach(([sectionTitle, content], index) => {
        htmlContent += 
        `
            <div class="textarea-container">
                <h2>${sectionTitle}</h2>
                <p>${content.replace(/\n/g, '<br>')}</p>
            </div>
        `;
    });

    htmlContent += `
        </div>
        </body>
        </html>
      `;

    newTab.document.open();
    newTab.document.write(htmlContent);
    newTab.document.close()
//   popupTitle.textContent = `Sections of specification ${specId}`;
  
//   popupTextareas.innerHTML = '';
//   Object.entries(sections).forEach(([section, content], index) => {
//     const container = document.createElement("div");
//     container.className = "textarea-container";

//     const textarea = document.createElement("textarea");
//     textarea.id = `section-${index}`;
//     textarea.value = `${section}\n\n${content}`
//     textarea.readOnly = true;

//     const copyBtn = document.createElement('button');
//     copyBtn.className = 'copy-btn';
//     copyBtn.textContent = 'Copy';
//     copyBtn.onclick = () => copyTextarea(`section-${index}`);

//     container.appendChild(textarea);
//     container.appendChild(copyBtn);
//     popupTextareas.appendChild(container);
//   });
  
//   sectionPopup.style.display = 'block';
//   document.body.style.overflow = 'hidden';
}

// Display batch results
function displayBatchResults(data) {
    resultsList.innerHTML = '';
    
    // Found documents
    Object.entries(data.results).forEach(([docId, url]) => {
        const resultItem = document.createElement('div');
        resultItem.className = 'result-item';
        resultItem.innerHTML = `
            <div class="result-header">
                <div class="result-id">${docId}</div>
                <div class="result-status status-found">Found</div>
            </div>
            <div class="result-url">
                <a href="${url}" target="_blank">${url}</a>
            </div>
        `;
        resultsList.appendChild(resultItem);
    });
    
    // Not found documents
    data.missing.forEach(docId => {
        const resultItem = document.createElement('div');
        resultItem.className = 'result-item';
        resultItem.innerHTML = `
            <div class="result-header">
                <div class="result-id">${docId}</div>
                <div class="result-status status-not-found">Not Found</div>
            </div>
        `;
        resultsList.appendChild(resultItem);
    });
    
    const foundCount = Object.keys(data.results).length;
    const totalCount = foundCount + data.missing.length;
    
    resultsStats.textContent = `Found ${foundCount} of ${totalCount} documents in ${data.search_time.toFixed(2)} seconds`;
    resultsContainer.style.display = 'block';
}

// Show loader
function showLoader() {
    loader.style.display = 'block';
}

// Hide loader
function hideLoader() {
    loader.style.display = 'none';
}

// Show error message
function showError(message) {
    resultsList.innerHTML = "";
    resultsStats.textContent = `Found 0 documents`;
    errorMessage.textContent = message;
    errorMessage.style.display = 'block';
}

// Hide error message
function hideError() {
    errorMessage.style.display = 'none';
}

// Enter key event for single search
docIdInput.addEventListener('keypress', (e) => {
    if (e.key === 'Enter') {
        searchBtn.click();
    }
});

keywordInput.addEventListener('keypress', (event)=>{
    if (event.key === "Enter"){
        keywordSearchBtn.click();
    }
})

expKeywordInput.addEventListener('keypress', (event)=>{
    if (event.key === "Enter"){
        keywordSearchBtn.click();
    }
})