this code should go into a separate controller/directive so it will work for both ingest and archive