• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geonetwork / geonetwork-ui / 12470799507

23 Dec 2024 05:45PM UTC coverage: 84.204% (-0.4%) from 84.621%
12470799507

Pull #1051

github

web-flow
Merge 9161179cf into 8c98ae01e
Pull Request #1051: [Editor]: Warn user if draft has been updated

3248 of 4338 branches covered (74.87%)

Branch coverage included in aggregate %.

68 of 72 new or added lines in 10 files covered. (94.44%)

11 existing lines in 2 files now uncovered.

9253 of 10508 relevant lines covered (88.06%)

199.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

77.27
/apps/metadata-editor/src/app/edit/edit-page.component.ts
1
import { CommonModule } from '@angular/common'
3✔
2
import {
3✔
3
  Component,
4
  ElementRef,
5
  OnDestroy,
6
  OnInit,
7
  ViewChild,
8
} from '@angular/core'
9
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'
3✔
10
import { ActivatedRoute, Router } from '@angular/router'
3✔
11
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
3✔
12
import { PublicationVersionError } from '@geonetwork-ui/common/domain/model/error'
3✔
13
import {
3✔
14
  EditorFacade,
15
  RecordFormComponent,
16
} from '@geonetwork-ui/feature/editor'
17
import {
3✔
18
  NotificationsContainerComponent,
19
  NotificationsService,
20
} from '@geonetwork-ui/feature/notifications'
21
import { ButtonComponent } from '@geonetwork-ui/ui/inputs'
3✔
22
import { TranslateModule, TranslateService } from '@ngx-translate/core'
3✔
23
import { combineLatest, filter, firstValueFrom, Subscription, take } from 'rxjs'
3✔
24
import { map, skip } from 'rxjs/operators'
3✔
25
import { SidebarComponent } from '../dashboard/sidebar/sidebar.component'
3✔
26
import { PageSelectorComponent } from './components/page-selector/page-selector.component'
3✔
27
import { TopToolbarComponent } from './components/top-toolbar/top-toolbar.component'
3✔
28

29
marker('editor.record.form.bottomButtons.comeBackLater')
3✔
30
marker('editor.record.form.bottomButtons.previous')
3✔
31
marker('editor.record.form.bottomButtons.next')
3✔
32

33
@Component({
34
  selector: 'md-editor-edit',
35
  templateUrl: './edit-page.component.html',
36
  styleUrls: ['./edit-page.component.css'],
37
  standalone: true,
38
  imports: [
39
    RecordFormComponent,
40
    CommonModule,
41
    ButtonComponent,
42
    MatProgressSpinnerModule,
43
    TopToolbarComponent,
44
    NotificationsContainerComponent,
45
    PageSelectorComponent,
46
    TranslateModule,
47
    SidebarComponent,
48
  ],
49
})
50
export class EditPageComponent implements OnInit, OnDestroy {
3✔
51
  subscription = new Subscription()
12✔
52

53
  currentPage$ = this.facade.currentPage$
12✔
54
  pagesLength$ = this.facade.editorConfig$.pipe(
12✔
55
    map((config) => config.pages.length)
10✔
56
  )
57
  isLastPage$ = combineLatest([this.currentPage$, this.pagesLength$]).pipe(
12✔
58
    map(([currentPage, pagesCount]) => currentPage >= pagesCount - 1)
10✔
59
  )
60
  hasRecordChanged$ = this.facade.hasRecordChanged$.pipe(skip(1))
12✔
61

62
  @ViewChild('scrollContainer') scrollContainer: ElementRef<HTMLElement>
63

64
  constructor(
65
    private route: ActivatedRoute,
12!
66
    private facade: EditorFacade,
12!
67
    private notificationsService: NotificationsService,
12!
68
    private translateService: TranslateService,
12!
69
    private router: Router
12✔
70
  ) {}
71

72
  ngOnInit(): void {
73
    const [currentRecord, currentRecordSource, currentRecordAlreadySaved] =
74
      this.route.snapshot.data['record']
10✔
75

76
    this.facade.openRecord(
10✔
77
      currentRecord,
78
      currentRecordSource,
79
      currentRecordAlreadySaved
80
    )
81

82
    this.subscription.add(
10✔
83
      this.facade.saveError$.subscribe((error) => {
84
        if (error instanceof PublicationVersionError) {
2✔
85
          this.notificationsService.showNotification(
1✔
86
            {
87
              type: 'error',
88
              title: this.translateService.instant(
89
                'editor.record.publishVersionError.title'
90
              ),
91
              text: this.translateService.instant(
92
                'editor.record.publishVersionError.body',
93
                { currentVersion: error.detectedApiVersion }
94
              ),
95
              closeMessage: this.translateService.instant(
96
                'editor.record.publishVersionError.closeMessage'
97
              ),
98
            },
99
            undefined,
100
            error
101
          )
102
        } else {
103
          this.notificationsService.showNotification(
1✔
104
            {
105
              type: 'error',
106
              title: this.translateService.instant(
107
                'editor.record.publishError.title'
108
              ),
109
              text: `${this.translateService.instant(
110
                'editor.record.publishError.body'
111
              )} ${error.message}`,
112
              closeMessage: this.translateService.instant(
113
                'editor.record.publishError.closeMessage'
114
              ),
115
            },
116
            undefined,
117
            error
118
          )
119
        }
120
      })
121
    )
122

123
    this.subscription.add(
10✔
124
      this.facade.saveSuccess$.subscribe(() => {
125
        this.notificationsService.showNotification(
1✔
126
          {
127
            type: 'success',
128
            title: this.translateService.instant(
129
              'editor.record.publishSuccess.title'
130
            ),
131
            text: `${this.translateService.instant(
132
              'editor.record.publishSuccess.body'
133
            )}`,
134
          },
135
          2500
136
        )
137
      })
138
    )
139

140
    this.subscription.add(
10✔
141
      this.facade.record$.subscribe((record) => {
142
        this.facade.checkHasRecordChanged(record)
11✔
143
      })
144
    )
145

146
    // if we're on the /create route, go to /edit/{uuid} on first change
147
    if (this.route.snapshot.routeConfig?.path.includes('create')) {
10✔
148
      this.subscription.add(
3✔
149
        this.facade.draftSaveSuccess$.pipe(take(1)).subscribe(() => {
150
          this.router.navigate(['edit', currentRecord.uniqueIdentifier], {
1✔
151
            replaceUrl: true,
152
          })
153
        })
154
      )
155
    }
156

157
    // if the record unique identifier changes, navigate to /edit/newUuid
158
    this.subscription.add(
10✔
159
      this.facade.record$
160
        .pipe(
161
          filter(
162
            (record) =>
163
              record?.uniqueIdentifier !== currentRecord.uniqueIdentifier
11✔
164
          ),
165
          take(1)
166
        )
167
        .subscribe((savedRecord) => {
168
          this.router.navigate(['edit', savedRecord.uniqueIdentifier])
1✔
169
        })
170
    )
171

172
    this.subscription.add(
10✔
173
      this.facade.record$.subscribe((record) => {
174
        this.facade.checkHasRecordChanged(record)
11✔
175
      })
176
    )
177
  }
178

179
  ngOnDestroy() {
180
    this.subscription.unsubscribe()
12✔
181
  }
182

183
  async previousPageButtonHandler() {
184
    const currentPage = await firstValueFrom(this.currentPage$)
×
185
    if (currentPage === 0) {
×
186
      this.router.navigate(['catalog', 'search'])
×
187
    } else {
188
      this.facade.setCurrentPage(currentPage - 1)
×
189
      this.scrollToTop()
×
190
    }
191
  }
192

193
  async nextPageButtonHandler() {
194
    const currentPage = await firstValueFrom(this.currentPage$)
×
195
    const pagesCount = await firstValueFrom(this.pagesLength$)
×
196
    if (currentPage < pagesCount - 1) {
×
197
      this.facade.setCurrentPage(currentPage + 1)
×
198
      this.scrollToTop()
×
199
    }
200
  }
201

202
  private scrollToTop() {
203
    this.scrollContainer.nativeElement.scroll({
×
204
      behavior: 'instant',
205
      top: 0,
206
    })
207
  }
208

209
  formatDate(date: Date): string {
NEW
210
    return date.toLocaleDateString(this.translateService.currentLang, {
×
211
      year: 'numeric',
212
      month: 'long',
213
      day: 'numeric',
214
      hour: 'numeric',
215
      minute: 'numeric',
216
    })
217
  }
218
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc