mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-06 03:15:48 -06:00
feat: Add functionality to delete notes
This commit is contained in:
@@ -11,9 +11,18 @@ extension WidgetPadding on Widget {
|
||||
Widget paddedSymmetrically({
|
||||
double horizontal = 0.0,
|
||||
double vertical = 0.0,
|
||||
bool sliver = false,
|
||||
}) {
|
||||
final insets =
|
||||
EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical);
|
||||
if (sliver) {
|
||||
return SliverPadding(
|
||||
padding: insets,
|
||||
sliver: this,
|
||||
);
|
||||
}
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: horizontal, vertical: vertical),
|
||||
padding: insets,
|
||||
child: this,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,6 +87,47 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateNote(NoteModel note) async {
|
||||
assert(state.status == LoadingStatus.loaded);
|
||||
final document = state.document!;
|
||||
final updatedNotes = document.notes.map((e) => e.id == note.id ? note : e);
|
||||
try {
|
||||
final updatedDocument = await _api.update(
|
||||
state.document!.copyWith(
|
||||
notes: updatedNotes,
|
||||
),
|
||||
);
|
||||
_notifier.notifyUpdated(updatedDocument);
|
||||
} on PaperlessApiException catch (e) {
|
||||
addError(
|
||||
TransientPaperlessApiError(
|
||||
code: e.code,
|
||||
details: e.details,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteNote(NoteModel note) async {
|
||||
assert(state.status == LoadingStatus.loaded,
|
||||
"Document data has to be loaded before calling this method.");
|
||||
assert(note.id != null, "Note id cannot be null.");
|
||||
try {
|
||||
final updatedDocument = await _api.deleteNote(
|
||||
state.document!,
|
||||
note.id!,
|
||||
);
|
||||
_notifier.notifyUpdated(updatedDocument);
|
||||
} on PaperlessApiException catch (e) {
|
||||
addError(
|
||||
TransientPaperlessApiError(
|
||||
code: e.code,
|
||||
details: e.details,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> assignAsn(
|
||||
DocumentModel document, {
|
||||
int? asn,
|
||||
|
||||
@@ -240,11 +240,6 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
context.read(),
|
||||
documentId: widget.id,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16,
|
||||
horizontal: 16,
|
||||
),
|
||||
child: TabBarView(
|
||||
children: [
|
||||
CustomScrollView(
|
||||
@@ -254,12 +249,14 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded =>
|
||||
DocumentOverviewWidget(
|
||||
LoadingStatus.loaded => DocumentOverviewWidget(
|
||||
document: state.document!,
|
||||
itemSpacing: _itemSpacing,
|
||||
queryString:
|
||||
widget.titleAndContentQueryString,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
@@ -277,6 +274,9 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
document: state.document!,
|
||||
queryString:
|
||||
widget.titleAndContentQueryString,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
@@ -290,11 +290,13 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded =>
|
||||
DocumentMetaDataWidget(
|
||||
LoadingStatus.loaded => DocumentMetaDataWidget(
|
||||
document: state.document!,
|
||||
itemSpacing: _itemSpacing,
|
||||
metaData: state.metaData!,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
@@ -309,8 +311,10 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
SimilarDocumentsView(
|
||||
pagingScrollController:
|
||||
_pagingScrollController,
|
||||
pagingScrollController: _pagingScrollController,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -323,24 +327,13 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded => DocumentNotesWidget(
|
||||
document: state.document!,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
},
|
||||
if (state.status == LoadingStatus.loaded)
|
||||
SliverToBoxAdapter(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
AddNoteRoute($extra: state.document!)
|
||||
.push(context);
|
||||
},
|
||||
icon: Icon(Icons.note_add_outlined),
|
||||
label: Text('Add note'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (hasMultiUserSupport)
|
||||
@@ -349,21 +342,29 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
slivers: [
|
||||
SliverOverlapInjector(
|
||||
handle: NestedScrollView
|
||||
.sliverOverlapAbsorberHandleFor(
|
||||
context),
|
||||
.sliverOverlapAbsorberHandleFor(context),
|
||||
),
|
||||
switch (state.status) {
|
||||
LoadingStatus.loaded =>
|
||||
DocumentPermissionsWidget(
|
||||
document: state.document!,
|
||||
).paddedSymmetrically(
|
||||
vertical: 16,
|
||||
sliver: true,
|
||||
),
|
||||
LoadingStatus.error => _buildErrorState(),
|
||||
_ => _buildLoadingState(),
|
||||
}
|
||||
],
|
||||
),
|
||||
],
|
||||
]
|
||||
.map(
|
||||
(child) => Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: child,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
|
||||
class DocumentNotesWidget extends StatelessWidget {
|
||||
final DocumentModel document;
|
||||
@@ -9,30 +14,69 @@ class DocumentNotesWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SliverList.builder(
|
||||
return SliverMainAxisGroup(
|
||||
slivers: [
|
||||
SliverList.separated(
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 16),
|
||||
itemBuilder: (context, index) {
|
||||
final note = document.notes.elementAt(index);
|
||||
return ListTile(
|
||||
title: Text(note.note),
|
||||
subtitle: Text(
|
||||
DateFormat.yMMMd(Localizations.localeOf(context).toString())
|
||||
.format(note.created)),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
return Card(
|
||||
// borderRadius: BorderRadius.circular(8),
|
||||
// elevation: 1,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (note.created != null)
|
||||
Text(
|
||||
DateFormat.yMMMd(
|
||||
Localizations.localeOf(context).toString())
|
||||
.addPattern('\u2014')
|
||||
.add_jm()
|
||||
.format(note.created!),
|
||||
style: Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(.5),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
note.note!,
|
||||
textAlign: TextAlign.justify,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Spacer(),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
// Push edit page
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {},
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
context.read<DocumentDetailsCubit>().deleteNote(note);
|
||||
showSnackBar(
|
||||
context,
|
||||
S.of(context)!.documentSuccessfullyUpdated,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
).padded(16),
|
||||
);
|
||||
},
|
||||
itemCount: document.notes.length,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class EditNotePage extends StatefulWidget {
|
||||
const EditNotePage({super.key});
|
||||
|
||||
@override
|
||||
State<EditNotePage> createState() => _EditNotePageState();
|
||||
}
|
||||
|
||||
class _EditNotePageState extends State<EditNotePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Placeholder();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_api/src/converters/local_date_time_json_converter.dart';
|
||||
@@ -95,6 +96,9 @@ class DocumentModel extends Equatable {
|
||||
String? archivedFileName,
|
||||
int? Function()? owner,
|
||||
bool? userCanChange,
|
||||
Iterable<NoteModel>? notes,
|
||||
Permissions? permissions,
|
||||
Iterable<CustomFieldModel>? customFields,
|
||||
}) {
|
||||
return DocumentModel(
|
||||
id: id,
|
||||
@@ -115,6 +119,9 @@ class DocumentModel extends Equatable {
|
||||
archivedFileName: archivedFileName ?? this.archivedFileName,
|
||||
owner: owner != null ? owner() : this.owner,
|
||||
userCanChange: userCanChange ?? this.userCanChange,
|
||||
customFields: customFields ?? this.customFields,
|
||||
notes: notes ?? this.notes,
|
||||
permissions: permissions ?? this.permissions,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,5 +142,8 @@ class DocumentModel extends Equatable {
|
||||
archivedFileName,
|
||||
owner,
|
||||
userCanChange,
|
||||
customFields,
|
||||
notes,
|
||||
permissions,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -28,3 +28,4 @@ export 'task/task.dart';
|
||||
export 'task/task_status.dart';
|
||||
export 'user_model.dart';
|
||||
export 'exception/exceptions.dart';
|
||||
export 'note_model.dart';
|
||||
|
||||
@@ -5,10 +5,10 @@ part 'note_model.g.dart';
|
||||
@freezed
|
||||
class NoteModel with _$NoteModel {
|
||||
const factory NoteModel({
|
||||
required int id,
|
||||
required String note,
|
||||
required DateTime created,
|
||||
required int document,
|
||||
required int? id,
|
||||
required String? note,
|
||||
required DateTime? created,
|
||||
required int? document,
|
||||
required int? user,
|
||||
}) = _NoteModel;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ abstract class PaperlessDocumentsApi {
|
||||
Future<DocumentModel> find(int id);
|
||||
Future<int> delete(DocumentModel doc);
|
||||
Future<DocumentMetaData> getMetaData(int id);
|
||||
Future<DocumentModel> deleteNote(DocumentModel document, int noteId);
|
||||
Future<Iterable<int>> bulkAction(BulkAction action);
|
||||
Future<Uint8List> getPreview(int docId);
|
||||
String getThumbnailUrl(int docId);
|
||||
|
||||
@@ -323,4 +323,22 @@ class PaperlessDocumentsApiImpl implements PaperlessDocumentsApi {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DocumentModel> deleteNote(DocumentModel document, int noteId) async {
|
||||
try {
|
||||
final response = await client.delete(
|
||||
"/api/documents/${document.id}/notes/?id=$noteId",
|
||||
options: Options(validateStatus: (status) => status == 200),
|
||||
);
|
||||
final notes =
|
||||
(response.data as List).map((e) => NoteModel.fromJson(e)).toList();
|
||||
|
||||
return document.copyWith(notes: notes);
|
||||
} on DioException catch (exception) {
|
||||
throw exception.unravel(
|
||||
orElse: const PaperlessApiException(ErrorCode.documentDeleteFailed),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
set -Euo pipefail
|
||||
|
||||
__script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
readonly __script_dir
|
||||
|
||||
pushd "$__script_dir/../"
|
||||
|
||||
pushd packages/paperless_api
|
||||
for dir in packages/*/ # list directories in the form "/tmp/dirname/"
|
||||
do
|
||||
pushd $dir
|
||||
echo "Installing dependencies for $dir"
|
||||
flutter packages pub get
|
||||
dart run build_runner build --delete-conflicting-outputs
|
||||
popd
|
||||
|
||||
pushd packages/mock_server
|
||||
flutter packages pub get
|
||||
popd
|
||||
done
|
||||
|
||||
flutter packages pub get
|
||||
flutter gen-l10n
|
||||
dart run build_runner build --delete-conflicting-outputs
|
||||
|
||||
popd
|
||||
|
||||
|
||||
Reference in New Issue
Block a user