2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-17 12:45:26 +00:00

Add model for InvenTreePartAttachment

This commit is contained in:
Oliver
2021-08-15 16:49:59 +10:00
parent 40805b2aff
commit ffd423cf9a
5 changed files with 78 additions and 32 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:inventree/api.dart';
import 'package:flutter/cupertino.dart';
import 'package:inventree/inventree/sentry.dart';
@ -44,8 +45,6 @@ class InvenTreeModel {
// Note: If the WEB_URL is the same (except for /api/) as URL then just leave blank
String WEB_URL = "";
String NAME = "Model";
String get webUrl {
if (api.isConnected()) {
@ -453,3 +452,60 @@ class InvenTreeModel {
}
class InvenTreeAttachment extends InvenTreeModel {
// Class representing an "attachment" file
InvenTreeAttachment() : super();
String get attachment => jsondata["attachment"] ?? '';
// Return the filename of the attachment
String get filename {
return attachment.split("/").last;
}
IconData get icon {
String fn = filename.toLowerCase();
if (fn.endsWith(".pdf")) {
return FontAwesomeIcons.filePdf;
} else if (fn.endsWith(".csv")) {
return FontAwesomeIcons.fileCsv;
} else if (fn.endsWith(".doc") || fn.endsWith(".docx")) {
return FontAwesomeIcons.fileWord;
} else if (fn.endsWith(".xls") || fn.endsWith(".xlsx")) {
return FontAwesomeIcons.fileExcel;
}
// Image formats
final List<String> img_formats = [
".png",
".jpg",
".gif",
".bmp",
".svg",
];
for (String fmt in img_formats) {
if (fn.endsWith(fmt)) {
return FontAwesomeIcons.fileImage;
}
}
return FontAwesomeIcons.fileAlt;
}
String get comment => jsondata["comment"] ?? '';
DateTime? get uploadDate {
if (jsondata.containsKey("upload_date")) {
return DateTime.tryParse(jsondata["upload_date"] ?? '');
} else {
return null;
}
}
InvenTreeAttachment.fromJson(Map<String, dynamic> json) : super.fromJson(json);
}