github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/elm/src/Pinned.elm (about)

     1  module Pinned exposing
     2      ( CommentState
     3      , ResourcePinState(..)
     4      , VersionPinState(..)
     5      , finishPinning
     6      , pinState
     7      , quitUnpinning
     8      , stable
     9      , startPinningTo
    10      , startUnpinning
    11      )
    12  
    13  
    14  type alias CommentState =
    15      { comment : String
    16      , pristineComment : String
    17      }
    18  
    19  
    20  type ResourcePinState version id comment
    21      = NotPinned
    22      | PinningTo id
    23      | PinnedDynamicallyTo comment version
    24      | UnpinningFrom comment version
    25      | PinnedStaticallyTo version
    26      | Switching comment version id
    27  
    28  
    29  type VersionPinState
    30      = Enabled
    31      | PinnedDynamically
    32      | NotThePinnedVersion
    33      | PinnedStatically Bool
    34      | Disabled
    35      | InTransition
    36  
    37  
    38  startPinningTo :
    39      id
    40      -> ResourcePinState version id CommentState
    41      -> ResourcePinState version id CommentState
    42  startPinningTo destination resourcePinState =
    43      case resourcePinState of
    44          NotPinned ->
    45              PinningTo destination
    46  
    47          PinnedDynamicallyTo comment version ->
    48              Switching comment version destination
    49  
    50          x ->
    51              x
    52  
    53  
    54  finishPinning :
    55      (id -> Maybe version)
    56      -> ResourcePinState version id CommentState
    57      -> ResourcePinState version id CommentState
    58  finishPinning lookup resourcePinState =
    59      case resourcePinState of
    60          PinningTo b ->
    61              lookup b
    62                  |> Maybe.map
    63                      (PinnedDynamicallyTo { comment = "", pristineComment = "" })
    64                  |> Maybe.withDefault NotPinned
    65  
    66          x ->
    67              x
    68  
    69  
    70  startUnpinning :
    71      ResourcePinState version id CommentState
    72      -> ResourcePinState version id CommentState
    73  startUnpinning resourcePinState =
    74      case resourcePinState of
    75          PinnedDynamicallyTo c v ->
    76              UnpinningFrom c v
    77  
    78          x ->
    79              x
    80  
    81  
    82  quitUnpinning :
    83      ResourcePinState version id CommentState
    84      -> ResourcePinState version id CommentState
    85  quitUnpinning resourcePinState =
    86      case resourcePinState of
    87          UnpinningFrom c v ->
    88              PinnedDynamicallyTo c v
    89  
    90          x ->
    91              x
    92  
    93  
    94  stable : ResourcePinState version id CommentState -> Maybe version
    95  stable version =
    96      case version of
    97          PinnedStaticallyTo v ->
    98              Just v
    99  
   100          PinnedDynamicallyTo _ v ->
   101              Just v
   102  
   103          _ ->
   104              Nothing
   105  
   106  
   107  pinState :
   108      version
   109      -> id
   110      -> ResourcePinState version id CommentState
   111      -> VersionPinState
   112  pinState version id resourcePinState =
   113      case resourcePinState of
   114          PinnedStaticallyTo v ->
   115              if v == version then
   116                  PinnedStatically False
   117  
   118              else
   119                  Disabled
   120  
   121          NotPinned ->
   122              Enabled
   123  
   124          PinningTo destination ->
   125              if destination == id then
   126                  InTransition
   127  
   128              else
   129                  Disabled
   130  
   131          PinnedDynamicallyTo _ v ->
   132              if v == version then
   133                  PinnedDynamically
   134  
   135              else
   136                  NotThePinnedVersion
   137  
   138          UnpinningFrom _ v ->
   139              if v == version then
   140                  InTransition
   141  
   142              else
   143                  Disabled
   144  
   145          Switching _ v destination ->
   146              if destination == id || v == version then
   147                  InTransition
   148  
   149              else
   150                  Disabled