Prechádzať zdrojové kódy

Note - scroll to latest section + auto-edit

Vijayakrishnan Krishnan 4 rokov pred
rodič
commit
03c72dae2e

+ 28 - 1
resources/views/app/patient/note/dashboard.blade.php

@@ -205,9 +205,16 @@
                         }
                         $packed = implode("^^^", $packed);
                         $shortcuts = $packed;
+                        $latestSectionTS = 0;
                         ?>
                         @foreach($note->sections as $section)
-                        <div class="p-3 border-bottom note-section {{ $section->is_initialized ? '' : 'pending-initialization' }}"
+                        <?php
+                        $sectionTS = strtotime($section->created_at);
+                        if($latestSectionTS === 0 || $latestSectionTS < $sectionTS) {
+                            $latestSectionTS = $sectionTS;
+                        }
+                        ?>
+                        <div data-ts={{$sectionTS}} class="p-3 border-bottom note-section {{ $section->is_initialized ? '' : 'pending-initialization' }}"
                              data-section-uid="{{ $section->uid }}"
                              data-section-template-uid="{{ $section->sectionTemplate->uid }}"
                              data-section-template-name="{{ $section->sectionTemplate->internal_name }}">
@@ -246,6 +253,8 @@
                     </div>
                 </div>
 
+                <span class="d-none latest-section-ts">{{ $latestSectionTS }}</span>
+
                 @if($note->bills->count())
                     <div class="mt-2 px-3">
                         <div class="d-flex align-items-center mb-2">
@@ -617,9 +626,27 @@
                         );
                     });
                 }
+                else {
+                    scrollToLatest();
+                }
 
             }
 
+            // scroll to latest created section
+            function scrollToLatest() {
+                window.setTimeout(function() {
+                    let latestSectionTS = $('.latest-section-ts');
+                    if(latestSectionTS.length) {
+                        let latestSection = $('.note-section[data-ts="' + latestSectionTS.text() + '"]');
+                        if(latestSection.length) {
+                            latestSection[0].scrollIntoView({behavior: "smooth", block: "center"});
+                            latestSection.find('.edit-trigger').first().click();
+                            console.log('DONE!');
+                        }
+                    }
+                }, 100);
+            }
+
             function initializeSection(_sectionUid, _sectionTemplateName) {
                 $.get('/get-default-section-data/' + _sectionTemplateName + '/{{$patient->uid}}' , function(_data) {
                     if(!_data) {