void updateDartdocStatus()

in pkg/web_app/lib/src/dartdoc_status.dart [11:89]


void updateDartdocStatus() {
  final List<String> packages = document
      .querySelectorAll('.version-table')
      .map((e) => e.dataset['package'])
      .where((s) => s != null && s.isNotEmpty)
      .cast<String>()
      .toSet()
      .toList();

  Future<void> update(String package) async {
    final List<Element> tables = document
        .querySelectorAll('.version-table')
        .where((e) => e.dataset['package'] == package)
        .toList();
    for (Element table in tables) {
      table.querySelectorAll('td.documentation').forEach((e) {
        e.dataset[_hasDocumentationAttr] = '-'; // unknown value
      });
    }

    try {
      final content =
          await HttpRequest.getString('/api/documentation/$package');
      final map = json.decode(content) as Map;
      final versionsList = map['versions'] as List;
      for (Map versionMap in versionsList.cast<Map>()) {
        final version = versionMap['version'] as String;
        final hasDocumentation = versionMap['hasDocumentation'] as bool;
        final status = versionMap['status'] as String;
        for (Element table in tables) {
          table
              .querySelectorAll('tr')
              .where((e) => e.dataset['version'] == version)
              .forEach(
            (row) {
              final docCol = row.querySelector('.documentation');
              if (docCol == null) return;
              final docLink = docCol.querySelector('a') as AnchorElement?;
              if (docLink == null) return;
              if (status == 'pending') {
                docCol.dataset[_hasDocumentationAttr] = '...';
                docLink.text = 'pending';
              } else if (hasDocumentation) {
                docCol.dataset[_hasDocumentationAttr] = '1';
              } else {
                docCol.dataset[_hasDocumentationAttr] = '0';
                docLink.href = '${docLink.href}log.txt';
                final img = docLink.querySelector('img.version-table-icon');
                if (img != null && img.dataset.containsKey('failed-icon')) {
                  img.setAttribute('src', img.dataset['failed-icon']!);
                } else {
                  docLink.text = 'failed';
                }
              }
            },
          );
        }
      }

      // clear unknown values
      for (Element table in tables) {
        table.querySelectorAll('td.documentation').forEach((docCol) {
          if (docCol.dataset[_hasDocumentationAttr] == '-') {
            final docLink = docCol.querySelector('a') as AnchorElement?;
            if (docLink != null) {
              docLink.remove();
            }
          }
        });
      }
    } catch (_) {
      // ignore errors
    }
  }

  for (String package in packages) {
    update(package);
  }
}