Use a minimum age of items to remove

In order to keep deleted items for a while, the periodic task can now
use a duration to only remove items with a certain age. This can be
used to ensure that a deleted item stays at least X days before it
will be removed from the database.

Refs: #347
This commit is contained in:
eikek
2021-08-15 12:28:42 +02:00
parent d136bb8166
commit f4a2b86ea8
27 changed files with 303 additions and 124 deletions

View File

@ -158,6 +158,7 @@ import Api.Model.CustomFieldValue exposing (CustomFieldValue)
import Api.Model.DirectionValue exposing (DirectionValue)
import Api.Model.EmailSettings exposing (EmailSettings)
import Api.Model.EmailSettingsList exposing (EmailSettingsList)
import Api.Model.EmptyTrashSetting exposing (EmptyTrashSetting)
import Api.Model.Equipment exposing (Equipment)
import Api.Model.EquipmentList exposing (EquipmentList)
import Api.Model.FolderDetail exposing (FolderDetail)
@ -999,13 +1000,14 @@ startClassifier flags receive =
startEmptyTrash :
Flags
-> EmptyTrashSetting
-> (Result Http.Error BasicResult -> msg)
-> Cmd msg
startEmptyTrash flags receive =
startEmptyTrash flags setting receive =
Http2.authPost
{ url = flags.config.baseUrl ++ "/api/v1/sec/collective/emptytrash/startonce"
, account = getAccount flags
, body = Http.emptyBody
, body = Http.jsonBody (Api.Model.EmptyTrashSetting.encode setting)
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
}

View File

@ -22,7 +22,6 @@ import Comp.ClassifierSettingsForm
import Comp.Dropdown
import Comp.EmptyTrashForm
import Comp.MenuBar as MB
import Data.CalEvent
import Data.DropdownStyle as DS
import Data.Flags exposing (Flags)
import Data.Language exposing (Language)
@ -54,11 +53,14 @@ type ClassifierResult
| ClassifierResultSubmitError String
| ClassifierResultOk
type EmptyTrashResult
= EmptyTrashResultInitial
| EmptyTrashResultHttpError Http.Error
| EmptyTrashResultSubmitError String
| EmptyTrashResultOk
| EmptyTrashResultInvalidForm
type FulltextReindexResult
= FulltextReindexInitial
@ -79,7 +81,7 @@ init flags settings =
Comp.ClassifierSettingsForm.init flags settings.classifier
( em, ec ) =
Comp.EmptyTrashForm.init flags settings.emptyTrashSchedule
Comp.EmptyTrashForm.init flags settings.emptyTrash
in
( { langModel =
Comp.Dropdown.makeSingleList
@ -101,24 +103,21 @@ init flags settings =
getSettings : Model -> Maybe CollectiveSettings
getSettings model =
Maybe.map
Maybe.map2
(\cls ->
{ language =
Comp.Dropdown.getSelected model.langModel
|> List.head
|> Maybe.map Data.Language.toIso3
|> Maybe.withDefault model.initSettings.language
, integrationEnabled = model.intEnabled
, classifier = cls
, emptyTrashSchedule =
Comp.EmptyTrashForm.getSettings model.emptyTrashModel
|> Maybe.withDefault Data.CalEvent.everyMonth
|> Data.CalEvent.makeEvent
}
)
(Comp.ClassifierSettingsForm.getSettings
model.classifierModel
\trash ->
{ language =
Comp.Dropdown.getSelected model.langModel
|> List.head
|> Maybe.map Data.Language.toIso3
|> Maybe.withDefault model.initSettings.language
, integrationEnabled = model.intEnabled
, classifier = cls
, emptyTrash = trash
}
)
(Comp.ClassifierSettingsForm.getSettings model.classifierModel)
(Comp.EmptyTrashForm.getSettings model.emptyTrashModel)
type Msg
@ -233,8 +232,20 @@ update flags msg model =
( model, Api.startClassifier flags StartClassifierResp, Nothing )
StartEmptyTrashTask ->
( model, Api.startEmptyTrash flags StartEmptyTrashResp, Nothing )
case getSettings model of
Just settings ->
( model
, Api.startEmptyTrash flags
settings.emptyTrash
StartEmptyTrashResp
, Nothing
)
Nothing ->
( { model | startEmptyTrashResult = EmptyTrashResultInvalidForm }
, Cmd.none
, Nothing
)
StartClassifierResp (Ok br) ->
( { model
@ -275,6 +286,7 @@ update flags msg model =
)
--- View2
@ -471,6 +483,7 @@ renderClassifierResultMessage texts result =
, ( S.successMessage, isSuccess )
, ( "hidden", result == ClassifierResultInitial )
]
, class "ml-2"
]
[ case result of
ClassifierResultInitial ->
@ -505,6 +518,7 @@ renderFulltextReindexResultMessage texts result =
FulltextReindexSubmitError m ->
text m
renderEmptyTrashResultMessage : Texts -> EmptyTrashResult -> Html msg
renderEmptyTrashResultMessage texts result =
let
@ -525,6 +539,7 @@ renderEmptyTrashResultMessage texts result =
, ( S.successMessage, isSuccess )
, ( "hidden", result == EmptyTrashResultInitial )
]
, class "ml-2"
]
[ case result of
EmptyTrashResultInitial ->
@ -538,4 +553,7 @@ renderEmptyTrashResultMessage texts result =
EmptyTrashResultSubmitError m ->
text m
EmptyTrashResultInvalidForm ->
text texts.emptyTrashStartInvalidForm
]

View File

@ -14,40 +14,36 @@ module Comp.EmptyTrashForm exposing
, view
)
import Api
import Api.Model.EmptyTrashSetting exposing (EmptyTrashSetting)
import Comp.CalEventInput
import Comp.Dropdown
import Comp.FixedDropdown
import Comp.IntField
import Data.CalEvent exposing (CalEvent)
import Data.DropdownStyle as DS
import Data.Flags exposing (Flags)
import Data.ListType exposing (ListType)
import Data.UiSettings exposing (UiSettings)
import Html exposing (..)
import Html.Attributes exposing (..)
import Http
import Markdown
import Messages.Comp.EmptyTrashForm exposing (Texts)
import Styles as S
import Util.Tag
type alias Model =
{ scheduleModel : Comp.CalEventInput.Model
, schedule : Maybe CalEvent
, minAgeModel : Comp.IntField.Model
, minAgeDays : Maybe Int
}
type Msg
= ScheduleMsg Comp.CalEventInput.Msg
| MinAgeMsg Comp.IntField.Msg
init : Flags -> String -> ( Model, Cmd Msg )
init flags schedule =
init : Flags -> EmptyTrashSetting -> ( Model, Cmd Msg )
init flags settings =
let
newSchedule =
Data.CalEvent.fromEvent schedule
Data.CalEvent.fromEvent settings.schedule
|> Maybe.withDefault Data.CalEvent.everyMonth
( cem, cec ) =
@ -55,14 +51,34 @@ init flags schedule =
in
( { scheduleModel = cem
, schedule = Just newSchedule
, minAgeModel = Comp.IntField.init (Just 0) Nothing False
, minAgeDays = Just <| millisToDays settings.minAge
}
, Cmd.map ScheduleMsg cec
)
getSettings : Model -> Maybe CalEvent
millisToDays : Int -> Int
millisToDays millis =
round <| toFloat millis / 1000 / 60 / 60 / 24
daysToMillis : Int -> Int
daysToMillis days =
days * 24 * 60 * 60 * 1000
getSettings : Model -> Maybe EmptyTrashSetting
getSettings model =
model.schedule
Maybe.map2
(\sch ->
\age ->
{ schedule = Data.CalEvent.makeEvent sch
, minAge = daysToMillis age
}
)
model.schedule
model.minAgeDays
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
@ -84,6 +100,18 @@ update flags msg model =
, Cmd.map ScheduleMsg cc
)
MinAgeMsg lmsg ->
let
( mm, newAge ) =
Comp.IntField.update lmsg model.minAgeModel
in
( { model
| minAgeModel = mm
, minAgeDays = newAge
}
, Cmd.none
)
--- View2
@ -103,4 +131,16 @@ view texts _ model =
model.scheduleModel
)
]
, div [ class "mb-4" ]
[ let
settings : Comp.IntField.ViewSettings
settings =
{ number = model.minAgeDays
, label = texts.minAge
, classes = ""
, info = texts.minAgeInfo
}
in
Html.map MinAgeMsg (Comp.IntField.view settings model.minAgeModel)
]
]

View File

@ -47,13 +47,13 @@ init min max opt =
tooLow : Model -> Int -> Bool
tooLow model n =
Maybe.map ((<) n) model.min
|> Maybe.withDefault (not model.optional)
|> Maybe.withDefault False
tooHigh : Model -> Int -> Bool
tooHigh model n =
Maybe.map ((>) n) model.max
|> Maybe.withDefault (not model.optional)
|> Maybe.withDefault False
update : Msg -> Model -> ( Model, Maybe Int )

View File

@ -40,6 +40,7 @@ type alias Texts =
, languageLabel : Language -> String
, classifierTaskStarted : String
, emptyTrashTaskStarted : String
, emptyTrashStartInvalidForm : String
, fulltextReindexSubmitted : String
, fulltextReindexOkMissing : String
, emptyTrash : String
@ -71,6 +72,7 @@ gb =
, languageLabel = Messages.Data.Language.gb
, classifierTaskStarted = "Classifier task started."
, emptyTrashTaskStarted = "Empty trash task started."
, emptyTrashStartInvalidForm = "The empty-trash form contains errors."
, fulltextReindexSubmitted = "Fulltext Re-Index started."
, fulltextReindexOkMissing =
"Please type OK in the field if you really want to start re-indexing your data."
@ -103,6 +105,7 @@ de =
, languageLabel = Messages.Data.Language.de
, classifierTaskStarted = "Kategorisierung gestartet."
, emptyTrashTaskStarted = "Papierkorb löschen gestartet."
, emptyTrashStartInvalidForm = "Das Papierkorb-Löschen Formular ist fehlerhaft!"
, fulltextReindexSubmitted = "Volltext Neu-Indexierung gestartet."
, fulltextReindexOkMissing =
"Bitte tippe OK in das Feld ein, wenn Du wirklich den Index neu erzeugen möchtest."

View File

@ -19,6 +19,8 @@ type alias Texts =
{ basics : Messages.Basics.Texts
, calEventInput : Messages.Comp.CalEventInput.Texts
, schedule : String
, minAge : String
, minAgeInfo : String
}
@ -27,6 +29,8 @@ gb =
{ basics = Messages.Basics.gb
, calEventInput = Messages.Comp.CalEventInput.gb
, schedule = "Schedule"
, minAge = "Minimum Age (Days)"
, minAgeInfo = "The minimum age in days of an items to be removed. The last-update time is used."
}
@ -35,4 +39,6 @@ de =
{ basics = Messages.Basics.de
, calEventInput = Messages.Comp.CalEventInput.de
, schedule = "Zeitplan"
, minAge = "Mindestalter (Tage)"
, minAgeInfo = "Das Mindestalter (in Tagen) der Dokumente, die gelöscht werden. Es wird das Datum der letzten Veränderung verwendet."
}